Function name: mb_substr_count()
Function description: The mb_substr_count() function is used to calculate the number of times a string appears in another string, and is case-insensitive.
Function usage: mb_substr_count(string $haystack, string $needle, string|null $encoding = null): int
parameter:
Return value: Returns the number of times a substring appears in the string.
Example:
$text = "Hello, I'm a PHP developer."; $substring = "php"; $count = mb_substr_count(mb_strtolower($text), mb_strtolower($substring)); echo "子字符串出现的次数为: " . $count;
Output: The number of times the substring appears is: 1
Description: In the above example, we used the mb_substr_count() function to calculate the number of times the substring "php" appears in the string "Hello, I'm a PHP developer." Since the function is case-insensitive, we used the mb_strtolower() function to convert the string to lowercase before the calculation. Finally, we output the calculation result as "The number of times the substring appears is: 1".