Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with unserialize()

Status
Not open for further replies.

petey

Programmer
Mar 25, 2001
383
US
Has anybody had this problem? Here's what's going on:

I serialize a large object and save it to the file system using this code:
Code:
if ($fp = fopen($objfile, 'w'))
fputs($fp, serialize($obj)); fclose($fp);
Then I read it back from the disk using this code:
Code:
$obj = unserialize(implode("", @file($objfile)));
This barfed whenever the serialized string contained a newline, because evidentally the newline was saved as "\n\r", and that carriage return was screwing up the unserialization. (I'm running Apache/PHP locally on my Windows XP) Here's the modified code that avoids this problem:
Code:
$obj = unserialize(str_replace("\r",'',implode("", @file($objfile))));
Anybody have any comments on this?

petey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top