adv Posted May 8, 2008 Share Posted May 8, 2008 <?php $message = "this is my test, of bad words"; $foundBadWord = filter($message); if($foundBadWord) { header("Location: ban.php"); exit; } echo $message; function filter($message) { //Get contents from file $Ban = file_get_contents ("filter.txt"); //Get contents from string(for testing) #$Ban = "tests\ntesting"; //put into a array $BanWords = explode("\n",$Ban); foreach($BanWords as $B) { //check for bad word if (strpos($message,$B)) { //found one return false; } } //none found return true; } ?> i saw this on this forum but the topic was solved but i have a question <?php foreach($BanWords as $B) { //check for bad word if (strpos($message,$B)) { //found one return false; } } //none found return true; ?> why does foreach return true if nothing is found .. it shouldn`t return false; ?? if (strpos($message,$B)) { //found one return false; } why does it returns false because this (strpos($message,$B)) is true .. it shouldn`t return true; ?? Link to comment https://forums.phpfreaks.com/topic/104697-return-question/ Share on other sites More sharing options...
conker87 Posted May 8, 2008 Share Posted May 8, 2008 Just swap them around. It should work either way. Link to comment https://forums.phpfreaks.com/topic/104697-return-question/#findComment-535817 Share on other sites More sharing options...
adv Posted May 8, 2008 Author Share Posted May 8, 2008 then why didn`t he swapped them too? don`t think is that simple :| Link to comment https://forums.phpfreaks.com/topic/104697-return-question/#findComment-535821 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.