Back to Samples

Search for a specific text within a string

$string = "Hello world. I'm looking for a needle in a long string."
$needle= "for"
strpos($string, $needle) = 25
findMe($string, $needle) = 25
findMe($string, "foo") = -1