mb_strpos
Find where the string first appears in another string
Function name: mb_strpos()
Applicable version: PHP 4 >= 4.0.6, PHP 5, PHP 7, PHP 8
Function Description: The mb_strpos() function is used to find the first occurrence location of another substring in one string. Similar to the strpos() function, but the mb_strpos() function can handle multibyte characters.
Syntax: mb_strpos(string $haystack, string $needle, int $offset = 0, string $encoding = null): int|false
parameter:
Return value:
Example:
// 示例1:在一个字符串中查找子字符串的位置$str = "Hello, World!"; $pos = mb_strpos($str, "World"); echo $pos; // 输出:7 // 示例2:在一个字符串中查找子字符串的位置,指定开始搜索的位置$str = "Hello, World!"; $pos = mb_strpos($str, "o", 5); echo $pos; // 输出:8 // 示例3:在一个多字节字符串中查找子字符串的位置,指定字符编码$str = "你好,世界!"; $pos = mb_strpos($str, "世界", 0, "UTF-8"); echo $pos; // 输出:6 // 示例4:未找到子字符串的情况下返回false $str = "Hello, World!"; $pos = mb_strpos($str, "abc"); var_dump($pos); // 输出:bool(false)
Notes: