php comprobar si la cadena contiene word
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
php chech si la cadena contiene
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
buscar php si la subcadena está en cadena
$result = strpos("haystack", "needle");
if ($result != false)
{
// text found
}
buscar php si la cadena contiene
if (strpos($string, 'substring') !== false) {
// do stuff
}
¿Cómo puedo comprobar si una cadena contiene una palabra específica?
$a = 'Hello world?';
if (strpos($a, 'Hello') !== false) { //PAY ATTENTION TO !==, not !=
echo 'true';
}
if (stripos($a, 'HELLO') !== false) { //Case insensitive
echo 'true';
}
php comprueba si la cadena contiene un char
$haystack = 'This is my haystack that we shall check'
$has_A = strpos($haystack, 'A') !== false;
$has_a = strpos($haystack, 'a') !== false;