Jump to content

serial/unserialize


dennismonsewicz

Recommended Posts

so it would turn this:

 

<?php

$arr = array("dog", "cat", "horse");

$ser = serialize($arr);

echo $ser;

?>

 

into this:

 

dog, cat, horse

 

No, serialize() isn't meant to be human readable, it's meant to be stored and later read by unserialize(). If you want the output you posted there you would use implode().

 

echo implode(', ', array("dog", "cat", "horse"));

 

Using your code to just show you what serialize makes it (and to show how it's not to be meant for human consumption) the output of serialize on the array is:

a:3:{i:0;s:3:"dog";i:1;s:3:"cat";i:2;s:5:"horse";}

Link to comment
Share on other sites

It's human readable if you know what it's saying...=P

a:3:{i:0;s:3:"dog";i:1;s:3:"cat";i:2;s:5:"horse";}

 

a:3 =>'this is an array of 3 elements'

{ => 'start of array'

i0;s:3:"dog"; => 'index 0 is a string of 3 characters and its value is 'dog'

i:1;s:3:"cat"; => 'index 1 is a string of 3 characters an its value is 'cat'

i:2;s:5:"horse"; => 'index 2 is a string of 5 characters and its value is 'horse'

} => 'end array'

 

See?  Very readable :)  same info you get from var_dump, but more compact.

Link to comment
Share on other sites

It's human readable if you know what it's saying...=P

 

Yes, but so is binary. serialize() is not made to be read by human USERS, there are other functions for that :D (of course I don't have to tell YOU that, Mr. function dictionary). That was my point, not that it couldn't be read.

 

=P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.