irkevin Posted January 28, 2009 Share Posted January 28, 2009 Hi, I've been searching for hours for a solution and now i'm stuck. I have this code function filterBadWords($str) { $badwords = array("barwords_goes_here","barwords_goes_here","barwords_goes_here"); $replacements = "*"; foreach ($badwords as $badword) { $str = eregi_replace($badword, str_repeat('*', strlen($badword)), $str); } return $str; } I created a mysql table, and store the bad words there. My question is : How do I replace the 'barwords_goes_here', with the data in the mysql table? Quote Link to comment Share on other sites More sharing options...
ratcateme Posted January 28, 2009 Share Posted January 28, 2009 im not sure there must be a better way i think but i would do something like function filterBadWords($str) { $result = mysql_query("SELECT `word` FROM `badwords`") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result) != null) { $str = eregi_replace($row['word'], str_repeat('*', strlen($badword)), $str); } return $str; } but like i say i am sure there would be a better mysql way but i dont know it sorry Scott. Quote Link to comment Share on other sites More sharing options...
irkevin Posted January 28, 2009 Author Share Posted January 28, 2009 Hey, its working it did what i expected. Thanks for your help the complete code. Had to change strlen($badword) to strlen($row['words']) <?php function filterBadWords($str) { include("../config.php"); $result = mysql_query("SELECT words FROM badword") or die(mysql_error()); $replacements = "*"; while($row = mysql_fetch_assoc($result)) { $str = eregi_replace($row['words'], str_repeat('*', strlen($row['words'])), $str); } return $str; } echo filterBadWords("your_badword_from_database"); ?> 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.