1

我需要计算字符串中子字符串的出现次数。

我的代码就像,

$str1 = "when he arrives, he want to open the door.";
$find_str = "he";

这里字符串“he”出现了 4 次。

我如何在 php 中找到它?

4

3 回答 3

4

使用substr_count

substr_count($str1, $find_str)
于 2013-06-28T09:55:34.143 回答
3

使用substr_count php 函数。

解决方案:

$str1 = "when he arrives, he want to open the door.";
$find_str = "he";

substr_count($str1, $find_str);
于 2013-06-28T09:55:39.383 回答
1
echo substr_count($str1, $find_str);
于 2013-06-28T09:55:44.250 回答