Find out if string is serialized variable

<?php
 
$string = "a:0:{}";
if(preg_match("/(a|O|s|b)\x3a[0-9]*?
((\x3a((\x7b?(.+)\x7d)|(\x22(.+)\x22\x3b)))|(\x3b))/", $string))
{
echo "Serialized.";
}
else
{
echo "Not serialized.";
}
 
?>

Download this snippet

If you need to check whether string is a serialized representation of variable(sic!) you can use this. But don't forget, string in serialized representation could be VERY big, so match work can be slow, even with fast preg_* functions.

Twitter Twitter

0 Comments to “ Find out if string is serialized variable”

Leave a Comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>