Howto check if a string contains another string php

Posted on February 12, 2015

Many times you want to check if a string contains a string in php.

Add this function to you library.

function stringContains($haystack, $needle)
{
	$pos = strpos($haystack, $needle);

	// Note our use of ===.  Simply == would not work as expected
	// because the position of 'a' was the 0th (first) character.
	if ($pos === false) {
	    return false;
	} else {
	    return true;
	}
}

No Replies to "Howto check if a string contains another string php"