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

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

WBOY
Release: 2016-06-13 13:25:17
Original
1085 people have browsed it

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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template