need help in updating function to modern php code preg replace

Started on the old forum in October 2017 · view the original in the archive · old links redirect here

4 replies · 144 views · started 9 years ago · 1 min read

2 participants
rajveer Developer · 104 posts #1

can someone please fix this error in function from gumslone gumchat v3 script

function is

function mb_unserialize($serial_str) {
    $out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':"$2";'", $serial_str);
    return unserialize($out);
}

and error is

PHP Warning:  preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead

it is used for user database settings where smileys and color is inserted in serialized kinda way then unserialized using this function above to use in script for turning smileys on off and selecting username colors aswell as ignore list

something else Fellow · 2,296 posts #2

Your above code is incorrect due to coding-talks [ php] bbcode - try using [ code] bbcode instead.

something else Fellow · 2,296 posts #4
function mb_unserialize($serial_str) {
    $out = preg_replace_callback('!s:(\d+):"(.*?)";!s', 
    function($m) 
    {
            return 's:' . strlen($m[2]) . ':\"' . $m[2] . '\";';
    },
    $serial_str);
    return unserialize($out);
}

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close