<?php $myarray = array(123,"abcdef",4.567,"another string"); $ser = serialize($myarray); $ff = fopen("C:\myfile","w"); fwrite($ff,$ser); fclose($ff);
$fr = fopen("C:\myfile","r"); $outser = fgets($fr,1000); fclose($fr); $outarray = unserialize($outser); print $outarray[0]."\n"; print $outarray[1]."\n"; print $outarray[2]."\n"; print $outarray[3]."\n"; print $outarray[4]."\n"; ?> -----Original Message----- From: Clark [mailto:[EMAIL PROTECTED]] Sent: Sunday, February 17, 2002 11:15 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] storing arrays I'm having trouble storing my array to a text file, utilizing serialize() and unserialize(). Could you please show a very basic layout of the proper way to serialize and unserialize and store that to a file? Thanks. "Matt" <[EMAIL PROTECTED]> wrote in message 001e01c1b7c0$404d5be0$059aa8c0@Pooch">news:001e01c1b7c0$404d5be0$059aa8c0@Pooch... > > ----- Original Message ----- > From: "Clark" <[EMAIL PROTECTED]> > Sent: Saturday, February 16, 2002 9:15 PM > > > > Two questions: > > > > 1) Is it possible to write an array to a file? > > Yes, serialize it first with http://www.php.net/serialize. You can also > place this in a db text field because it will be a character representation. > > > 2) Is it possible to specify the name of the key to each item of an array > > when you get the array using file(). > > When retrieving the saved array, unserialize it, and you'll get the same > array back. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php