NYCPHP Meetup

NYPHP.org

[nycphp-talk] Unseralize help needed.

Hall, Leam lhall at smartronix.com
Fri Nov 6 12:50:36 EST 2009


Morning all!

I've been working on the "pull an array from a file" again and trying to implement the "unserialize" suggestion. Cant seem to make it work. Here's the draft:

####

echo "fred";
$my_info = array('me' => 'mi', 'myself' => 'numerouno',  'i' => 'id' );
$fred = serialize($my_info);
$my_file = fopen( '/tmp/me.ser', 'w');
fwrite($my_file, $fred);
fclose($my_file);
echo "<p> $fred.";
$new_fred = array();
$new_fred_line = file_get_contents('/tmp/me.ser');
echo "<p>$new_fred_line is here.";
$new_fred = unserialize($new_fred_line);
$new_fred_me = $new_fred['me'];
echo "<p> new_fred is $new_fred. ";

####

Produces:

####

fred 
a:3:{s:2:"me";s:2:"mi";s:6:"myself";s:9:"numerouno";s:1:"i";s:2:"id";}. 
a:3:{s:2:"me";s:2:"mi";s:6:"myself";s:9:"numerouno";s:1:"i";s:2:"id";} is here. 
new_fred is Array. 

####

Trying to get $new_fred to be an array and duplicate of $my_info. Thoughts?
Leam
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20091106/20fa1424/attachment.html>


More information about the talk mailing list