PHP substr_count() 函数

定义和用法

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

语法

substr_count(string,substring,start,length)
参数 描述
string 必需。规定要检查的字符串。
substring 必需。规定要检索的字符串。
start 可选。规定在字符串中何处开始搜索。
length 可选。规定搜索的长度。

例子

<?php
echo substr_count("Hello world. The world is nice","world");
?>

输出:

2