-3

So i found this wordpress plugin, and it's the only one that offers what i need, but it's outdated :/ This is the error:

Deprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead

And this is the code that causes the error:

$brform = preg_replace('/<p>(<input\stype="hidden"(?:.*?))<\/p>/isme', "'<div style=\'display:none;\'>'.\"\n\".str_replace('<br>', '', str_replace('<br />', '', stripslashes_deep('\\1'))).\"\n\".'</div>'", $form);

I know the answer is in here, but i can't get it to work on this line of code, that's why i'm asking in here. How to do it when all this html and CSS is in there?

  • Try to replace that function as shown here : http://stackoverflow.com/questions/19245205/replace-deprecated-preg-replace-e-with-preg-replace-callback – Milap Jan 09 '16 at 10:04
  • I tried to do that, but with no luck. I'm not sure where to break it up when all this html and css is in there – patrick furbo Jan 09 '16 at 10:16

1 Answers1

1

You can use an anonymous function to pass the matches to your function:

$result = preg_replace_callback(
    "/\{([<>])([a-zA-Z0-9_]*)(\?{0,1})([a-zA-Z0-9_]*)\}(.*)\{\\1\/\\2\}/isU",
    function($m) { return CallFunction($m[1], $m[2], $m[3], $m[4], $m[5]); },
    $result
);

Apart from being faster, this will also properly handle double quotes in your string. Your current code using /e would convert a double quote " into \".

Source : Replace deprecated preg_replace /e with preg_replace_callback

Community
  • 1
  • 1
Milap
  • 6,915
  • 8
  • 26
  • 46