Home  >  Article  >  Backend Development  >  php的preg_replace正则表达式,该如何解决

php的preg_replace正则表达式,该如何解决

WBOY
WBOYOriginal
2016-06-13 13:25:171052browse

php的preg_replace正则表达式
比如,判断是否存在XXXX字符串,如果是,则替换前后的尖括号,最后变成[任意个字符XXXX任意个字符]输出。

------解决方案--------------------
preg_replace('//s','[$1]',$str); //少了防止贪婪匹配
------解决方案--------------------

PHP code
$str = "";
$k = 'XXXX';
echo preg_replace("/]*?{$k}[^>]*)>/", '[$1]', $str); <div class="clear">
                 
              
              
        
            </div>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn