Username:   Password:  

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.";
}
 
?>

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.

Tags

regex PHP preg_match serialization