[英]php regexp exclude
我用它来清除字体标签中的html:
$html = '<font class="textmiddle" color="red">toto</font>' ;
$clean = preg_replace('/<font[^>]*>/', '', $html) ;
$clean = preg_replace('/<\/font>/', '', $clean) ;
它像一种魅力。
但是,当html字符串是:
$html = '<font class="textmiddle" color="<%= color.importanttext %>">toto</font>' ;
然后结果不是预期的结果:
">toto
尝试
<?php
$html = '<font class="textmiddle" color="<%= color.importanttext %>">toto</font>' ;
$clean = preg_replace('/<font\s.*">/SimU', '', $html) ;
echo $clean;
?>
但请注意,您得到了
toto</font>
在输出中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.