str_starts_with
Vérifiez si la chaîne commence par la sous-chaîne donnée
Nom de la fonction: str_starts_with ()
Fonction Fonction: détermine si une chaîne commence par le préfixe spécifié.
Version applicable: PHP 8.0.0 et plus.
Syntaxe: bool str_starts_with (String $ Haystack, String $ aiguille)
paramètre:
Valeur de retour:
Exemple:
$haystack = "Hello, world!"; $needle = "Hello"; if (str_starts_with($haystack, $needle)) { echo "字符串以指定前缀开始"; } else { echo "字符串不以指定前缀开始"; }
Sortir:
字符串以指定前缀开始
Notes:
substr($haystack, 0, strlen($needle)) === $needle
.