1

I have a problem. This is what I have:

$file_contents = preg_replace("!{$ldq}\*.*?\*{$rdq}!se","",$file_contents);

And I get a error saying that I need to replace preg_replace with preg_replace callback. And when I try to make it to preg_replace_callback this is what I end up with:

$file_contents = preg_replace_callback(
    "!{$ldq}\*.*?\*{$rdq}!se",
    function($matches) {
          return "";
    },
    $file_contents);

And then I end up with a new error saying

preg_replace_callback(): Modifier /e cannot be used with replacement callback

What have I done wrong?

Tushar Gupta - curioustushar
  • 58,085
  • 24
  • 103
  • 107
user3368977
  • 35
  • 2
  • 6
  • Don't use the `e` switch in the regexp for your preg_replace_callback(), simply `"!{$ldq}\*.*?\*{$rdq}!s",` – Mark Baker Mar 07 '15 at 19:04
  • You do not get an _error_, you get a _notice_ or a _warning_. If the flag is deprecated that does not mean it does not work. – arkascha Mar 07 '15 at 19:08
  • 1
    in the present case you don't need the e modifier at all since your replacement is a fixed string (an empty string here), so remove it, that's all: `preg_replace("!{$ldq}\*.*?\*{$rdq}!s", "", $file_contents);` – Casimir et Hippolyte Mar 07 '15 at 20:34

0 Answers0