1$myString = 'Hello Bob how are you?';
2if (strpos($myString, 'Bob') !== false) {
3 echo "My string contains Bob";
4}
1if (strpos($haystack,$needle) !== false) {
2 echo "$haystack contains $needle";
3}
1<?php
2$word = "fox";
3$mystring = "The quick brown fox jumps over the lazy dog";
4
5// Test if string contains the word
6if(strpos($mystring, $word) !== false){
7 echo "Word Found!";
8} else{
9 echo "Word Not Found!";
10}
11?>
1// returns true if $needle is a substring of $haystack
2function contains($haystack, $needle){
3 return strpos($haystack, $needle) !== false;
4}