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

MultiformeIngegno

  • Messages: 1 337

Pandos

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

MultiformeIngegno

  • Messages: 1 337

Nao

  • Dadman with a boy
  • Messages: 16 082

MultiformeIngegno

  • Messages: 1 337

Nao

  • Dadman with a boy
  • Messages: 16 082

MultiformeIngegno

  • Messages: 1 337
Ehm... this should be the only one left (preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead)
Code: [Sélectionner]
$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
  • Messages: 16 082
On first sight, I'd say...
- Add _callback in the function call,
- remove the 'e' modifier,
- and replace the replacement string with...

Code: [Sélectionner]
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

  • Messages: 1 337
Will try tomorrow :)
Posté : 25 Janvier 2014 à 20:03

Nao what's the goal of the regex? Is it to replace all [ before smg inside all nested levels inside [$tag] tags with [ ..?
Posté : 26 Janvier 2014 à 02:03

What about..

Code: [Sélectionner]
$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);
Citation de MultiformeIngegno le 26 Janvier 2014 à 02:28
What about..

Code: [Sélectionner]
$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
  • Messages: 16 082

MultiformeIngegno

  • Messages: 1 337