Re: serialize & unserialize
| From: | Gabor Hojtsy | Date: | Sat, 17 Jul 2004 22:07:01 +0000 |
| Subject: | Re: serialize & unserialize | ||
| References: | 1 | Groups: | php.mirrors |
| Request: | Send a blank email to php-mirrors+get-25399@lists.php.net to get a copy of this message | ||
Please use the same versions on both hosts, so they use and understand the same format. And also ask such questions next time on php-general@lists.php.net (our support mailing list).
Regards,
Gabor Hojtsy
Alexey írta:
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.