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