0

i am trying to remove everything in between html comments <!-- REMOVE --> in php using regex. can anyone lend a hand please

$str = preg_replace('/\<!--.*\-->/', '', $str);
t q
  • 4,593
  • 8
  • 56
  • 91

1 Answers1

1

Try preg_replace('/<!--.*-->/sU', '', $str);

Rob
  • 12,659
  • 4
  • 39
  • 56
  • -1, How this could match ``... some text ...``? Might be a better solution would be to use ``non-greedy`` parameter. – Cylian May 10 '12 at 04:22
  • @Cylian, `some text` is not in an html comment. So it's not supposed to match. By the way, it's already using `non-greedy` matching – Rob May 10 '12 at 04:25
  • @Rob:Point to notice here that, OP here wants to remove the data between comments. So, isn't that case, ``some text`` will get removed? – Cylian May 10 '12 at 04:27
  • The question is very confusingly worded, "in between comments" suggests just that – remove *everything between* (multiple) comments. Editing for clarity. – Benji XVI Jun 12 '15 at 14:32