0
<br style="clear: both">

The following regex doesn't work for me, what am I doing wrong?

return preg_replace('#<br[^>]+style="clear:both"[^/>]#is', '',  $output);

thank you.

Andy Lester
  • 91,102
  • 13
  • 100
  • 152
matt
  • 42,713
  • 103
  • 264
  • 397

3 Answers3

1

If your string is always:

<br style="clear: both">

You can use str_replace instead:

return str_replace('<br style="clear: both">', '',  $output);

Beware that you shouldn't use regex for html manipulation.

Use some parser HTML instead.

Community
  • 1
  • 1
Sarfraz
  • 377,238
  • 77
  • 533
  • 578
1

You may escape chars like =, :, <, >, etc. Something like this:

<?php    
return preg_replace('#\<br[^>]+style\=\"clear\:both\"[^/>]#is', '',  $output);
?>

More better example:

<?php
return preg_replace('#\<br*.?\>#is', '',  $output);
?>
Mark Pegasov
  • 5,109
  • 9
  • 26
  • 30
  • No, those characters have no special meaning, so escaping them is pointless. Also, the `*.?` in your second suggestion should be `.*?`. – Alan Moore Feb 25 '11 at 20:55
0

Try this :

#<br *style="clear: *both"/?>#is
soju
  • 25,111
  • 3
  • 68
  • 70