NYCPHP Meetup

NYPHP.org

[nycphp-talk] Unseralize help needed.

Andy Dirnberger dirn at dirnonline.com
Fri Nov 6 12:57:08 EST 2009


On Fri, Nov 6, 2009 at 12:50 PM, Hall, Leam <lhall at smartronix.com> wrote:
> 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
>

Have you tried do a print_r with $new_fred? Calling echo $ARRAY_VAR
will output "Array."

echo "<p> new_fred is " . print_r($new_fred, true) . ". ";



More information about the talk mailing list