mb_strpos
Trouver où la chaîne apparaît d'abord dans une autre chaîne
Nom de la fonction: MB_STRPOS ()
Version applicable: PHP 4> = 4.0.6, PHP 5, PHP 7, PHP 8
Fonction Description: La fonction MB_STRPOS () est utilisée pour trouver le premier emplacement d'occurrence d'une autre sous-chaîne dans une chaîne. Semblable à la fonction STRPOS (), mais la fonction MB_STRPOS () peut gérer des caractères multi -ytets.
Syntaxe: MB_STRPOS (String $ $ Haystack, String $ Needle, int $ offset = 0, String $ coding = null): int | false
paramètre:
Valeur de retour:
Exemple:
// 示例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: