The Most Accurate strpos Implementation

strpos in PHP works in a different way. If you are used to Java then it will come as no surprise that you will have your head scratching into confusion why it does not give the correct output.

So far in the strpos PHP page, contributors gave their own versions of strpos. The most accurate and the function that worked the way I wanted it to the same way that indexOf works in Java is by contributor teddanzig@yahoo.com.

This is his function.

function strposa($haystack, $needle) { 
    $pos=strpos($haystack, $needle); 
    if ($pos !== false) { 
        return $pos; 
    } 
    else { 
	return -1; 
    } 
}

Donations appreciated. Every little $ helps. Or click Google +1. Or play the short video on the upper right of this page.

Related Posts Plugin for WordPress, Blogger...