How do I make use of serialized data from MySQL?
Ho开发者_StackOverflow中文版w can I extract the serialized values of a string stored in MySQL? The values look something like this: a:{s1:./... }
. What is this?
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()
.
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);
精彩评论