How can I extract the serialized values of a string stored in MySQL? The values look something like this: a:{s1:./... }
. What is this?
views:
57answers:
2
+4
A:
PHP has a serialize()
function which turns any variable into a string like that.
echo serialize(array('foo', 3, array('bar' => 'BAR')));
// a:3:{i:0;s:3:"foo";i:1;i:3;i:2;a:1:{s:3:"bar";s:3:"BAR";}}
To return it to its original object, call unserialize()
.
nickf
2009-11-12 13:00:18
thanks:-) . it helps me to find for perl ;)
joe
2009-11-12 14:12:37
A:
PHP::Serialization - simple flexible means of converting the output of PHP's serialize() into the equivalent Perl memory structure, and vice versa.
use PHP::Serialization qw(serialize unserialize);
my $encoded = serialize({ a => 1, b => 2});
my $hashref = unserialize($encoded);
joe
2009-11-12 14:08:49