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
  • 86,927
  • 13
  • 98
  • 148
matt
  • 40,185
  • 99
  • 257
  • 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
  • 367,681
  • 72
  • 526
  • 573
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
  • 4,879
  • 9
  • 25
  • 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
  • 24,553
  • 3
  • 65
  • 68