php vérifie si la chaîne contient un mot
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
php chech si la chaîne contient
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
php trouve si la sous-chaîne est dans une chaîne
$result = strpos("haystack", "needle");
if ($result != false)
{
// text found
}
php trouve si la chaîne contient
if (strpos($string, 'substring') !== false) {
// do stuff
}
Comment vérifier si une chaîne contient un mot spécifique?
$a = 'Hello world?';
if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
echo 'true';
}
php vérifie si la chaîne contient un caractère
$haystack = 'This is my haystack that we shall check'
$has_A = strpos($haystack, 'A') !== false;
$has_a = strpos($haystack, 'a') !== false;