Current location: Hot Scripts Forums » Programming Languages » PHP » How do I write an array to a file?


How do I write an array to a file?

Reply
  #1 (permalink)  
Old 03-30-04, 06:24 AM
bark bark is offline
New Member
 
Join Date: Mar 2004
Location: Oslo, Norway
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Question How do I write an array to a file?

Hi

Does anybody know how to write arrays to file, and still maintain the array functions?

I'm trying to write a message board, very similar to a simple guestbook, and I need these messages to be stored in an array. When viewing the message board I want the newest message on top. I'm also planning to delete messages older than a certain amount of time.

I know all this is possible by sorting the messages into an array, but I'm not sure how to write the array to a file, and then later read the array data from the same file when viewing the message board. Is it even possible? Or does anybody know of another way of doing this?

(I've searched PHP.net for a function like this, but all I can find is IMPLODE, and that doesn't keep the array structure I need.)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-30-04, 11:47 AM
Mud Mud is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Southern California
Posts: 94
Thanks: 0
Thanked 0 Times in 0 Posts
cant u just keep the array structure
$Arrayname = array(stuff, stuff, stuff, stuff); not sure about other stuff but use a mysql database if u have the resources your life will be easier!
__________________
http://websoftblog.com/ - Web Software Blog
http://www.seekpire.com/ Make money searching!
http://www.gamingwise.com/ flash games!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-30-04, 01:28 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hi there,

implode()/explode() really only works for value-only/one-dimension array. If your array is more complicated than this, use serialize()/unserialize(). Use serialize() to flatten the array to write to your file, and unserialize() it (stored as one line) when you read it from the file.

HTH.
__________________
Blavv =|
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP write to text file veeco Script Requests 2 02-10-10 03:48 PM
write to file tiny PHP 18 05-21-04 06:50 PM
write to beginning of file or reverse an array of binary data abtimoteo Perl 1 01-20-04 11:09 AM
linking to iframe not working :( j0d JavaScript 5 01-19-04 09:14 PM
Write form data to file dragge PHP 1 12-27-03 08:26 PM


All times are GMT -5. The time now is 12:55 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.