php中如何使用substr_count函数

php中如何使用substr_count函数

这篇文章主要介绍php中如何使用substr_count函数,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

php substr_count函数用于统计一个字符串,在另一个字符串中出现次数,其语法是substr_count(string,substring,start,length),参数string 必需,是规定被检查的字符串;substring 必需,规定要搜索的字符串。

php中如何使用substr_count函数

php substr_count函数怎么用?

作用:统计一个字符串,在另一个字符串中出现次数

语法:

substr_count(string,substring,start,length)

参数:

string 必需。规定被检查的字符串。

substring 必需。规定要搜索的字符串。

start 可选。规定在字符串中何处开始搜索。

length 可选。规定搜索的长度。

说明:

计算子串在字符串中出现的次数。子串是区分大小写的。该函数不计数重叠的子串。如果 start 参数加上 length 参数大于字符串长度,则该函数生成一个警告。

php substr_count()函数使用示例1

<?php
echo substr_count("I love php.I'm study in php.cn","php");
?>

输出:

2

php substr_count()函数使用示例2

<?php
 $str = "This is php.cn test";
echo substr_count($str,"is",3,9);
?>

输出:

1

以上是php中如何使用substr_count函数的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注行业资讯频道!