<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