2011-02-25 84 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