1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1// returns true if $needle is a substring of $haystack
2function contains($haystack, $needle){
3 return strpos($haystack, $needle) !== false;
4}
1phpCopy<?php
2$mystring = "This is a PHP program.";
3
4if (strpos($mystring, "program.") !== false) {
5 echo("True");
6}
7?>
8