2011-02-25 83 views
0
<br style="clear: both"> 

下面的正则表达式不适合我,我做错了什么?php preg_replace删除<br>风格attr

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

谢谢。

+0

没有按因为你没有匹配“明确:”和“两个”之间的空格 – soju 2011-02-25 16:55:39

回答

0

试试这个:

#<br *style="clear: *both"/?>#is 
1

您可以逃脱像=字符,<>等 事情是这样的:

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

更多更好的例子:

<?php 
return preg_replace('#\<br*.?\>#is', '', $output); 
?> 
+0

不,这些角色没有特别的意义,所以逃避它们是毫无意义的。另外,第二个建议中的'*。?'应该是'。*?'。 – 2011-02-25 20:55:17