search for string in string php code example
Example 1: php check if string contains word
$myString = 'Hello Bob how are you?';
if (strpos($myString, 'Bob') !== false) {
echo "My string contains Bob";
}
Example 2: php needle haystack
//Find the position of the first occurrence of a substring in a string
$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);
Example 3: php find string in string
$pos = strpos("find the position of X in here", "X");
Example 4: strpos
strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) : int