Answered by : tomatentim
$string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string\n";
}
Source : https://www.php.net/manual/de/function.str-contains.php | Last Update : Fri, 30 Jul 21
Answered by : munyira-samson
$a = 'How are you?';
if (strpos($a, 'are') !== false) { echo 'true';
}
Source : https://stackoverflow.com/questions/4366730/how-do-i-check-if-a-string-contains-a-specific-word | Last Update : Sun, 25 Oct 20
Answered by : snippets
$str = 'Hello World!';
if (strpos($str, 'World') !== false) { echo 'true';
}
Source : | Last Update : Tue, 01 Mar 22
Answered by : ignatius-yuda
if (str_contains('How are you', 'are')) { echo 'true';
}
Source : https://stackoverflow.com/questions/4366730/how-do-i-check-if-a-string-contains-a-specific-word | Last Update : Mon, 14 Mar 22
Answered by : kaotik
<?php
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}
?>
Source : https://www.php.net/manual/en/function.strpos.php | Last Update : Fri, 20 Mar 20
Answered by : gtamborero
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
Source : https://www.php.net/manual/es/function.strpos.php | Last Update : Wed, 27 May 20
Answered by : quin-pullens
if (strpos($a, 'are') !== false) { echo 'true';
}
Source : https://stackoverflow.com/questions/4366730/how-do-i-check-if-a-string-contains-a-specific-word | Last Update : Thu, 09 Jul 20
Answered by : saritune-tune
string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) { echo "The string 'lazy' was found in the string\n";
}
Source : | Last Update : Fri, 12 Aug 22
Answered by : innocent-ibis-cmudez4ctzye
// For php < 8
/** * Determine if a string contains a given substring. * * @param string $haystack * @param string $needle * @return bool */
function str_contains($haystack, $needle)
{ return $needle !== '' && self::strpos($haystack, $needle) !== false;
}
Source : | Last Update : Thu, 13 Oct 22