PHP中的substr_count()函数

substr_count()函数用于计算子字符串的数量。

语法

substr_count(str,substr,begin,len)

参数

  • str-要检查的字符串

  • substr-要搜索的字符串

  • begin-从哪里开始搜索字符串

  • len-搜索的长度

返回

substr_count()函数返回子字符串在字符串中出现的次数。

示例

以下是一个例子-

<?php
   $str = 'This is our example!'; echo strlen($str);
   echo "\n"; echo substr_count($str, 'our');
?>

输出结果

20
1