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; ?? Quote Link to comment 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. Quote Link to comment 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 :| Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.