-
-
Save cobyan/f4914b5bc507b9891a4d746def97b172 to your computer and use it in GitHub Desktop.
This function will replace a given text with a new value in a serialized string
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 | |
/** | |
* This function will replace a given text with a new value | |
* in a serialized string | |
* | |
* @param string $input serialized value to seek | |
* @param string $search text to be replaced | |
* @param string $replace replacement text | |
* @return string new serialized string | |
*/ | |
function serialize_replace($input, $search, $replace) { | |
$ua = unserialize($input); | |
$replace_callback = function (&$value, $key, $data) { | |
if(!is_int($value)) | |
$value = str_replace($data['search'], $data['replace'], $value); | |
}; | |
array_walk_recursive($ua, $replace_callback , ['search' => $search, 'replace' => $replace]); | |
$b = serialize($ua); | |
return $b; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment