PHP

php中substr_count函数怎么使用

小亿
91
2024-06-12 17:25:06
栏目: 编程语言
PHP开发者专用服务器,限时0元免费领! 查看>>

substr_count函数用于计算一个字符串中某个子字符串出现的次数。

语法: int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] )

参数:

示例:

$str = "Hello, World! Hello, PHP!";
$count = substr_count($str, "Hello");
echo $count; // 输出:2

上面的示例中,substr_count函数会在字符串$str中查找子字符串"Hello"出现的次数,并将结果存储在$count变量中。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

相关推荐:php中substr_count函数使用要注意哪些事项

0
看了该问题的人还看了