$bigString = "I am a really big realtor in the bay area"; $pattern = "realtor"; $i = 0; $j = 0; $bigStringLen = strlen($bigString); $patternLen = strlen($pattern); $found = false; while ($i <= ($bigStringLen - $patternLen)) { if ($bigString[$i] == $pattern[$j]) { } else { $j=0; } $i++; $j++; if ($j >= $patternLen) { $found = true; break; } } if ($found) { print "found at " . ($i-$patternLen) . "\n"; } else { echo "\nnot found\n"; }