Skip to content

Instantly share code, notes, and snippets.

@TheHiddenHaku
Forked from SimonEast/gist:1117476
Last active August 29, 2015 14:08
Show Gist options
  • Save TheHiddenHaku/41f270649b8c2e3801f6 to your computer and use it in GitHub Desktop.
Save TheHiddenHaku/41f270649b8c2e3801f6 to your computer and use it in GitHub Desktop.
Recursive unserialize functions
<?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