function strStr($haystack, $needle) {
if ($needle == "") {
return 0;
}
$i = $j = 0;
while(isset($haystack[$i]) && isset($needle[$j])){
if ($haystack[$i] == $needle[$j]) {
$i++;
$j++;
}else{
$i = $i - $j + 1;
$j = 0;
}
}
if($j == strlen($needle)){
return $i-$j;
}
return -1;
}
网友评论