-
-
Save TheHiddenHaku/41f270649b8c2e3801f6 to your computer and use it in GitHub Desktop.
Recursive unserialize functions
This file contains hidden or 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 | |
// Next two functions taken from a commenter on http://php.net/manual/en/function.unserialize.php | |
function unserialize_recursive($val) { | |
//$pattern = "/.*\{(.*)\}/"; | |
if(is_serialized($val)){ | |
$val = trim($val); | |
$ret = unserialize($val); | |
if (is_array($ret)) { | |
foreach($ret as &$r) $r = unserialize_recursive($r); | |
} | |
return $ret; | |
} elseif (is_array($val)) { | |
foreach($val as &$r) $r = unserialize_recursive($r); | |
return $val; | |
} else { return $val; } | |
} | |
function is_serialized($val) { | |
if (!is_string($val)) return false; | |
if (trim($val) == "") return false; | |
$val = trim($val); | |
if (preg_match('/^(i|s|a|o|d):.*{/si', $val) > 0) return true; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment