2

Okay, so I'm slightly confused. Here is the code I have now, but I just found out the e modifier is deprecated. How do I convert it to a preg_replace_callback()? I still haven't figured it out.

$post = preg_replace("/\[code\]([^] )\[\/code\]/e", 'code(\'$1\')', $post);
HamZa
  • 14,671
  • 11
  • 54
  • 75
Jake
  • 1,469
  • 4
  • 19
  • 40
  • This question has been added to the [Stack Overflow Regular Expression FAQ](http://stackoverflow.com/a/22944075/2736496), under "Modifiers". – aliteralmind Apr 10 '14 at 00:38

1 Answers1

6

If memory serves, preg_replace_callback() gives you the results of a $match from preg_match() as input, and expects the final result as output. So you'd need to write a function that returns e.g. "code('{$match[1]}')".

It can be an inline function, naturally, if php 5.3 is an option:

preg_replace_callback($regex, function($match) {
  // do stuff
  return $stuff;
}, $subject);
Denis de Bernardy
  • 75,850
  • 13
  • 131
  • 154