Since you're using strstr, you can replace it with stristr, which is the case insensitive version
if(stristr($_GET[q],$term)==false)
Question
if someone searches "TestING" it should still read as "testing". I have a php file included into my webpages search to block certain terms. but i have to add each case in for every word. is there a quick fix so the case does not matter?
<?
$blocked=array('nude','nsfw','xrated');
?>
La solution 2
Since you're using strstr, you can replace it with stristr, which is the case insensitive version
if(stristr($_GET[q],$term)==false)
Autres conseils
Another way of doing things instead of always checking with strtolower
is instead of in_array
, use this function.
function in_arrayi($needle, $haystack) {
return in_array(strtolower($needle), array_map('strtolower', $haystack));
}
See http://us2.php.net/manual/en/function.in-array.php#89256
You can make everyting lowercase using strtolower.
$var1 = "Hello";
$var2 = "hello";
if (strtolower($var1) == strtolower($var2)) {
echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}
Or you can use strcasecmp.
$var1 = "Hello";
$var2 = "hello";
if (strcasecmp($var1, $var2) == 0) {
echo '$var1 is equal to $var2 in a case-insensitive string comparison';
}