Aeva: preg_replace(): The /e modifier is deprecated, use preg_replace_callback

MultiformeIngegno

  • Posts: 1,337

Pandos

  • Living on the edge of Wedge
  • Posts: 635
# dpkg-reconfigure brain
error: brain is not installed or configured

MultiformeIngegno

  • Posts: 1,337

Nao

  • Dadman with a boy
  • Posts: 16,079

MultiformeIngegno

  • Posts: 1,337

Nao

  • Dadman with a boy
  • Posts: 16,079

MultiformeIngegno

  • Posts: 1,337
Ehm... this should be the only one left (preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead)
Code: [Select]
$message = preg_replace('~\[' . $tag . ']((?>[^[]|\[(?!/?' . $tag . '])|(?R))+?)\[/' . $tag . ']~ie',
"'[" . $tag . "]' . str_ireplace('[smg', '[smg', '$1') . '[/" . $tag . "]'", $message);
Aeva-Subs.php:2546

Nao

  • Dadman with a boy
  • Posts: 16,079
On first sight, I'd say...
- Add _callback in the function call,
- remove the 'e' modifier,
- and replace the replacement string with...

Code: [Select]
function ($match) use ($tag) { return '[' . $tag . ']' . str_ireplace('[smg', '[smg', $match[1]) . '[/' . $tag . ']'; }

It's not a complicated task to rewrite these, really. My versions are PHP 5.3-only though, as usual.

MultiformeIngegno

  • Posts: 1,337
Will try tomorrow :)
Posted: January 25th, 2014, 08:03 PM

Nao what's the goal of the regex? Is it to replace all [ before smg inside all nested levels inside [$tag] tags with [ ..?
Posted: January 26th, 2014, 02:03 AM

What about..

Code: [Select]
$pattern = '~(\[' . $tag . '])((?>[^[]++|\[(?!/?+' . $tag . '])|(?R))*+)(\[/'
         . $tag . '])~i';
$message = preg_replace_callback($pattern,
                                 function ($m) {
                                     return $m[1]
                                          . str_ireplace('[smg', '[smg', $m[2])
                                          . $m[3];
                                 }, $message);
Quote from MultiformeIngegno on January 26th, 2014, 02:28 AM
What about..

Code: [Select]
$pattern = '~(\[' . $tag . '])((?>[^[]++|\[(?!/?+' . $tag . '])|(?R))*+)(\[/'
         . $tag . '])~i';
$message = preg_replace_callback($pattern,
                                 function ($m) {
                                     return $m[1]
                                          . str_ireplace('[smg', '[smg', $m[2])
                                          . $m[3];
                                 }, $message);
Seems to work (I don't get any error). How can I test it didn't break anything?

Nao

  • Dadman with a boy
  • Posts: 16,079

MultiformeIngegno

  • Posts: 1,337