0

I just need a bit of help with my ereg_replace changed to preg_replace..

ereg_replace('<caption.*</caption>', '', $match);

and I've tried

preg_replace('/<caption.*</caption>/', '', $match);

but it doesn't work.. and it says "Warning: preg_replace(): Unknown modifier 'c'"

I'm new to this kinda thing.. so any help would be appreciated :)

SoulieBaby
  • 5,405
  • 25
  • 95
  • 145
  • Possible duplicate of [How can I convert ereg expressions to preg in PHP?](https://stackoverflow.com/questions/6270004/how-can-i-convert-ereg-expressions-to-preg-in-php) – Toto Jun 03 '19 at 10:46

1 Answers1

1

The 'c' in question is the one in </caption> in your original regex. When the parser sees the /, it assumes that it's an ending delimiter, the regex is over, and it's looking for modifier flags. Not recognizing a modifier flag called c it throws the error you're seeing.

So you could fix things by escaping the slashes. In my mind, though, it might be more convenient to use a non-slash character (I'm partial to #) as your delimiter:

preg_replace('#<caption.*</caption>#', '', $match);
rjz
  • 16,182
  • 3
  • 36
  • 35
  • Thanks so much, that worked.. See now I didn't even know you could use # lol not so good with regexp :( – SoulieBaby May 08 '12 at 05:17
  • 1
    PHP's actually pretty open-minded about the delimiter...definitely a source of unnecessary confusion at times :^) – rjz May 08 '12 at 05:18