<br style="clear: both">
下面的正則表達式不適合我,我做錯了什麼?php preg_replace刪除<br>風格attr
return preg_replace('#<br[^>]+style="clear:both"[^/>]#is', '', $output);
謝謝。
<br style="clear: both">
下面的正則表達式不適合我,我做錯了什麼?php preg_replace刪除<br>風格attr
return preg_replace('#<br[^>]+style="clear:both"[^/>]#is', '', $output);
謝謝。
如果字符串始終是:
<br style="clear: both">
您可以使用str_replace
代替:
return str_replace('<br style="clear: both">', '', $output);
Beware that you shouldn't use regex for html manipulation.
改爲使用一些解析器HTML。
是的,應該更有效率 – soju 2011-02-25 16:57:31
試試這個:
#<br *style="clear: *both"/?>#is
您可以逃脫像=字符,:,<,>等 事情是這樣的:
<?php
return preg_replace('#\<br[^>]+style\=\"clear\:both\"[^/>]#is', '', $output);
?>
更多更好的例子:
<?php
return preg_replace('#\<br*.?\>#is', '', $output);
?>
不,這些角色沒有特別的意義,所以逃避它們是毫無意義的。另外,第二個建議中的'*。?'應該是'。*?'。 – 2011-02-25 20:55:17
沒有按因爲你沒有匹配「明確:」和「兩個」之間的空格 – soju 2011-02-25 16:55:39