1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1$string = 'The lazy fox jumped over the fence';
2
3if (str_contains($string, 'lazy')) {
4 echo "The string 'lazy' was found in the string\n";
5}
6
7
1$a = 'How are you?';
2
3if (strpos($a, 'are') !== false) {
4 echo 'true';
5}
6
1// returns true if $needle is a substring of $haystack
2function contains($haystack, $needle){
3 return strpos($haystack, $needle) !== false;
4}