Pazako Posted October 19, 2009 Share Posted October 19, 2009 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; } ?> Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/ Share on other sites More sharing options...
waynew Posted October 19, 2009 Share Posted October 19, 2009 <?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; } ?> Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/#findComment-939988 Share on other sites More sharing options...
jonsjava Posted October 19, 2009 Share Posted October 19, 2009 <?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 Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/#findComment-939991 Share on other sites More sharing options...
Pazako Posted October 19, 2009 Author Share Posted October 19, 2009 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! Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/#findComment-939992 Share on other sites More sharing options...
jonsjava Posted October 19, 2009 Share Posted October 19, 2009 oops. forgot. I re-worked my version to handle arrays. nm. Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/#findComment-939995 Share on other sites More sharing options...
waynew Posted October 19, 2009 Share Posted October 19, 2009 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? Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/#findComment-939997 Share on other sites More sharing options...
Pazako Posted October 19, 2009 Author Share Posted October 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/178275-solved-help-please-testing-a-string-for-list-content/#findComment-940003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.