preg_match和preg_match_all的区别
preg_match和preg_match_all的区别
preg_match只匹配一次,preg_match_all是全文匹配,即所有跟表达式一致的都找出来。举个例子:abc
1、取出符号里的字符。preg_match_all("/(w)+/","abc",$abc);print_r($abc);
显示结果为
Array( [0] = Array ( [0] = a [1] = b [2] = c )。- php中preg_match和preg_match_all的区别
[1] = Array ( [0] = a [1] = b [2] = c )
)
2、preg_match("/(w)+/","abc",$abc);print_r($abc);
显示结果
Array( [0] = a [1] = a)
这两个函数的区别就是:preg_match_all()搜索匹配全部情况;preg_match()搜索匹配到一个后终止。