$string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string
";
}
$str = 'Hello World!';
if (strpos($str, 'World') !== false) {
echo 'true';
}
if (str_contains('How are you', 'are')) {
echo 'true';
}
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
if (strpos($a, 'are') !== false) {
echo 'true';
}
str_contains(string $haystack , string $needle);
string = 'The lazy fox jumped over the fence';
if (str_contains($string, 'lazy')) {
echo "The string 'lazy' was found in the string
";
}
// 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;
}