Heim  >  Artikel  >  Backend-Entwicklung  >  问个正则表达式,如何排除<br>

问个正则表达式,如何排除<br>

WBOY
WBOYOriginal
2016-06-13 13:35:36848Durchsuche

问个正则表达式,怎么排除

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

--><?php $str = 'img我b有110www<br>有110110好呀';
echo preg_replace('/(img|110|b)/i', "<b>\${1}</b>", $str);
?>


目的是指定的字符粗体显示,怎么排除
,不让
粗体显示。


------解决方案--------------------
echo preg_replace('/(img|110|b\b)/i', "\${1}", $str);

echo preg_replace('/(img|110|b(?!r))/i', "\${1}", $str);

------解决方案--------------------
?!r
------解决方案--------------------
PHP code

'/(?<font color="#e78608">------解决方案--------------------</font><br>如果你需要考虑复杂点的情况,正则式就稍微复杂点,注意标签html标签内的img,110,b<br>
PHP code
$str = '<img  src="img/110/b.jpg" alt=" 问个正则表达式,如何排除<br&gt " >我img我b有110www<br>有110110好呀';
echo preg_replace('#(?=[^>]*(?=\1',$str); <div class="clear">
                 
              
              
        
            </div>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn