PHP substr_count() 函數(shù)
定義和用法
substr_count() 函數(shù)計(jì)算子串在字符串中出現(xiàn)的次數(shù)。
語法
substr_count(string,substring,start,length)
| 參數(shù) | 描述 |
|---|---|
| string | 必需。規(guī)定要檢查的字符串。 |
| substring | 必需。規(guī)定要檢索的字符串。 |
| start | 可選。規(guī)定在字符串中何處開始搜索。 |
| length | 可選。規(guī)定搜索的長(zhǎng)度。 |
例子
<?php
echo substr_count("Hello world. The world is nice","world");
?>
輸出:
2