Determine if PHP String Contains a Substring
This PHP function returns boolean true if the substring is contained within the string. If not it returns false.
function contains($haystack, $needle) {
if ($haystack=="" || $needle=="") { return false; }
return strpos(strtoupper($haystack), strtoupper($needle)) !== false;
}
Example:
$string = "Mary had a little lamb and it's fleece was white as snow";
$substring = "little lamb";
if (contains($string, $substring )) {
print "TRUE";
} else {
print "FALSE";
}
Result: TRUE