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
https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658467
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
https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658483
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.

Link to comment
https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658485
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
https://forums.phpfreaks.com/topic/127268-serialunserialize/#findComment-658489
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.