Skip to content

Instantly share code, notes, and snippets.

@cobyan
Created Jun 12, 2016
Embed
What would you like to do?
This function will replace a given text with a new value in a serialized string
<?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