PHP Conference Japan 2024

mb_substr_count

(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)

mb_substr_count計算子字串出現次數

說明

mb_substr_count(字串 $haystack, 字串 $needle, ?字串 $encoding = null): 整數

計算 needle 子字串在 haystack 字串 中出現的次數。

參數

haystack

被檢查的 字串

needle

要尋找的 字串

encoding

encoding 參數是字元編碼。如果省略或為 null,則會使用內部字元編碼值。

返回值

needle 子字串在 haystack 字串 中出現的次數。

更新日誌

版本 說明
8.0.0 encoding 現在可以為 null。

範例

範例 #1 mb_substr_count() 範例

<?php
echo mb_substr_count("This is a test", "is"); // 輸出 2
?>

參見

新增註記

使用者提供的註記

此頁面沒有使用者提供的註記。
To Top