Jump to content

[SOLVED] Help Please: Testing a string for list content


Pazako

Recommended Posts

I have a list called $NO_LIST that is the list of things I want rejected if found in a string, it appears to get through, but always allow any words as though it was ignoring my code. Am I missing something? I've tried a few different ways and this is the one I think looks best, thanks for any help you may have!

 

<?php
$NO_LIST = array('punished','scanning','error','fire','L$0','population','tier','month','contest','play','info','winner','payout','score','pot','tracker','pack','display','welcome','ride','fish','hour','sploder','avatars','party','pay ','scan','campaign','tenant','vacant','letter','stats','prize','campus');
function NoList($input)
{
for ($i = 0; $i < count($NO_LIST); $i++)
{
	$input = strtolower($input);
	$pos = strpos($input, $NO_LIST[$i]);
	if ($pos > -1) return false;
}
return true;
}
?>

<?php
$NO_LIST = array('punished','scanning','error','fire','L$0','population','tier','month','contest','play','info','winner','payout','score','pot','tracker','pack','display','welcome','ride','fish','hour','sploder','avatars','party','pay ','scan','campaign','tenant','vacant','letter','stats','prize','campus');

function NoList($input,$NO_LIST)
{
   foreach($NO_LIST as $bad_word){
         if(stristr(strtolower($input),$bad_word)){
             return false;
        }
   }
   return true;
}
?>

<?php
function NoList($input){
$NO_LIST = array('punished','scanning','error','fire','L$0','population','tier','month','contest','play','info','winner','payout','score','pot','tracker','pack','display','welcome','ride','fish','hour','sploder','avatars','party','pay ','scan','campaign','tenant','vacant','letter','stats','prize','campus');
if (stristr($input,$NO_LIST)){
	return false;
}
else{
	return true;
}
}

$data = "you will be PUnIsHED";
if (!NoList($data)){
print "clean";
}

you can push an array into stristr

So can php functions not see public variables?

 

Also, I need to check with the site 'Im uploading to if all those commands work, if so then thanks much!

 

Your functions shouldn't be dependent on outside variables. What if you want to use the same function on a different array?

The array isn't meant to be changed except for manually at the moment, but I understand what you mean. I have some experience in other programming fields and this kind of thing needs to happen there too. I believe when I first made this that stristr wasn't working because of an old php version on the server - but it all seems fine now. Thanks all for your input. The first response is the one that worked the best :P

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.