In the past, I've accomplished this (in all sorts of different languages) by converting your string variable to upper or lower case and comparing against an uppercase or lowercase string literal. That is to say:
if (strpos(strtoupper($string), "STRINGINASTRING") !== false) {
echo "The String is in the string!";
}
Also, note the use of the strpos
function instead of your in_string
declaration.
This methodology only calls the string conversion function once, since you already know the literal string you should be comparing your variable to, you can simply define it yourself as all uppercase or all lowercase (used with strtolower); take your pick.
One of the niceties behind this concept is it is applicable in languages that don't have case insensitive functions. Seems more universal to me; but on the other hand, having functions to do the same job is quiet convenient...