PHP Periksa apakah string berisi Word
$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";
}
$string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string\n";
}
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
$a = 'How are you?';
if (strpos($a, 'are') !== false) {
echo 'true';
}
if (str_contains('How are you', 'are')) {
echo 'true';
}
// returns true if $needle is a substring of $haystack
function contains($haystack, $needle){
return strpos($haystack, $needle) !== false;
}