Created
May 29, 2012 10:46
-
-
Save olimortimer/2825946 to your computer and use it in GitHub Desktop.
PHP: Serialize Check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// There's no built in function to check if data is serialized or not | |
// other than trying to unserialize it, and receiving an error if it isn't... | |
function is_serialized($data){ | |
if(trim($data) == "") { | |
return false; | |
} | |
if(preg_match("/^(i|s|a|o|d)(.*);/si",$data)) { | |
return true; | |
} | |
return false; | |
} | |
if(is_serialized($data)) | |
$undata = unserialize($data); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment