serialize & unserialize
| From: | Alexey | Date: | Sat, 17 Jul 2004 11:50:14 +0000 |
| Subject: | serialize & unserialize | ||
| Groups: | php.mirrors | ||
| Request: | Send a blank email to php-mirrors+get-25398@lists.php.net to get a copy of this message | ||
Hello, webmaster!
Recently I collided with a surprising problem.
I made a script which creates an array with some informatnion,
serializes this array and writes to the file. Very simple.
<?
$ar=array(
//array
);
$new=serialize($ar);
R_fwrite('new.txt',$new); // function, which writes to the file
?>
Ok, this works in my localhost server (Windows XP, Apache 1.3, PHP
4.3.0) and in the Internet (Linux, Apache/1.3.28 (Unix), PHP
Version 4.3.4). BUT! I created a file new.txt in the Internet, which contains a
serialized array, and then I download it to my computer. After that
I tried to read it and unserialize in order to continue use this
array.
<?
$file="new.txt";
$fopen=fopen($file,r);
flock($fopen, LOCK_SH);
$fread=fread($fopen,filesize($file);
flock($fopen, LOCK_UN);
$string=unserialize($fread);
?>
Surprisingly, it doesnt works! I mean, in WindowsXP I cannot unserialize an
object which I serialized in Linux! I tested every line and I see:
<? echo $fread; ?> works (I see a string in browser), but command
<? echo $string; ?> doesn't! It returns an empty string... Why
could it be? But it certainly works if I serialize&unserialize
only in localhost or only in server.
Beforehand thanks.
--
Best regards,
Alexey
http://www.osiacat.strana.de/
============================
[chasse au hibou (fr.)]