當前位置: 首頁> 函數類別大全> mb_substr_count

mb_substr_count

計算子字符串出現次數
名稱:mb_substr_count
分類:多字節字符串
所屬語言:php
一句話介紹:計算一個字符串在另一個字符串中出現的次數,不區分大小寫

函數名稱:mb_substr_count()

函數描述:mb_substr_count() 函數用於計算一個字符串在另一個字符串中出現的次數,不區分大小寫。

函數用法: mb_substr_count(string $haystack, string $needle, string|null $encoding = null): int

參數:

  • $haystack:必需,要搜索的字符串。
  • $needle:必需,要搜索的子字符串。
  • $encoding:可選,指定字符編碼。默認為內部字符編碼。

返回值: 返回子字符串在字符串中出現的次數。

示例:

 $text = "Hello, I'm a PHP developer."; $substring = "php"; $count = mb_substr_count(mb_strtolower($text), mb_strtolower($substring)); echo "子字符串出现的次数为: " . $count;

輸出: 子字符串出現的次數為: 1

說明: 上述示例中,我們使用了mb_substr_count() 函數來計算子字符串"php" 在字符串"Hello, I'm a PHP developer." 中出現的次數。由於該函數不區分大小寫,我們在計算之前使用了mb_strtolower() 函數將字符串轉換為小寫。最後,我們將計算結果輸出為"子字符串出現的次數為:1"。

同類函數
  • 獲取按指定寬度截斷的字符串 mb_strimwidth

    mb_strimwidth

    獲取按指定寬度截斷的字符串
  • 使用回調執行正則表達式搜索,並使用多字節支持替換 mb_ereg_replace_callback

    mb_ereg_replace_callback

    使用回調執行正則表達式搜索,並使用多字節
  • 將字符編碼為HTML 數字字符串引用 mb_encode_numericentity

    mb_encode_numericentity

    將字符編碼為HTML數字字符串引用
  • 大小寫不敏感地在字符串中查找一個字符串最後出現的位置 mb_strripos

    mb_strripos

    大小寫不敏感地在字符串中查找一個字符串最
  • 設置/獲取字符編碼的檢測順序 mb_detect_order

    mb_detect_order

    設置/獲取字符編碼的檢測順序
  • 使用正則表達式分割多字節字符串 mb_split

    mb_split

    使用正則表達式分割多字節字符串
  • 返回所有支持的編碼的數組 mb_list_encodings

    mb_list_encodings

    返回所有支持的編碼的數組
  • 返回字符串的寬度 mb_strwidth

    mb_strwidth

    返回字符串的寬度
熱門文章