1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1$result = strpos("haystack", "needle");
2
3if ($result != false)
4{
5 // text found
6}
1if (strpos($haystack,$needle) !== false) {
2 echo "$haystack contains $needle";
3}
1$haystack = 'This is my haystack that we shall check'
2$has_A = strpos($haystack, 'A') !== false;
3$has_a = strpos($haystack, 'a') !== false;
4
1// returns true if $needle is a substring of $haystack
2function contains($haystack, $needle){
3 return strpos($haystack, $needle) !== false;
4}