首页 > 文章列表 > PHP中的substr_count()函数

PHP中的substr_count()函数

函数 substr_count PHP中的
402 2023-08-20

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

语法

substr_count(str,substr,begin,len)

参数

  • str − 要检查的字符串

  • substr − 要搜索的字符串

  • begin − 在字符串中开始搜索的位置

  • len − 搜索的长度

Return

的中文翻译为:

返回

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

Example

的中文翻译为:

示例

The following is an example −

实时演示

<?php
   $str = 'This is our example!'; echo strlen($str);
   echo "

"; echo substr_count($str, 'our'); ?>

输出

20
1