Home > Backend Development > PHP Tutorial > 求正则表达式 计算字符串长度解决思路

求正则表达式 计算字符串长度解决思路

WBOY
Release: 2016-06-13 13:25:26
Original
874 people have browsed it

求正则表达式 计算字符串长度
$str = "asd你好[哈哈][你好][]"
计算符号包括里面[]的个数
$str长度应该是2个:[]符号里面没有内容不被计算
$strstr = "asd你好[哈哈][你好]"
长度也是2个

------解决方案--------------------

PHP code

preg_match_all("@\[.*?\]@",$strstr,$result);
echo count($result[0]) <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