PHP Verifique se a string contém palavras
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
Grepper
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
// this method is new with PHP 8 and above
$haystack = "Damn, I wonder if this string contains a comma.";
if (str_contains($haystack, ",")) {
echo "There is a comma!!";
}
$str = 'Hello World!';
if (strpos($str, 'World') !== false) {
echo 'true';
}
$result = strpos("haystack", "needle");
if ($result != false)
{
// text found
}
$myString = 'Hello Learn Tech Tips (Zidane)?';
if (strpos($myString, 'Zidane') !== false) {
echo "This string contains Zidane";
}
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}