dk4210 Posted March 10, 2011 Share Posted March 10, 2011 Hi guys, I have the following code, How can I query the database for the bad words and the replacements and make it work. $ad_title2 = $ad_title; $ad_body2 = $ad_body; $wordlist = "sh%t:cr*p|dang:d*ng|shoot:sh**t"; $words = explode('|', $wordlist); foreach ($words as $word) { list($match, $replacement) = explode(':', $word); $ad_title2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_title2); $ad_body2 = preg_replace("/([^a-z^A-Z]?)($match)([^a-z^A-Z]?)/i", "$1".$replacement."$3", $ad_body2); } Here is my table structure Table name is badwords I have 3 columns id | word | r_word Any help would be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
dk4210 Posted March 10, 2011 Author Share Posted March 10, 2011 Anybody want to take a stab at it? Quote Link to comment Share on other sites More sharing options...
MadLittleMods Posted March 10, 2011 Share Posted March 10, 2011 Try: Find: $wordlist = "sh%t:cr*p|dang:d*ng|shoot:sh**t"; Replace: $search_for_bad_words = mysql_query("SELECT * FROM badwords WHERE 1"); $seperate_text = "|"; $entry_seperate_text = ":"; while($row = mysql_fetch_array($search_for_bad_words)) { $wordlist = $wordlist.$seperate_text.$row[word].$entry_seperate_text.$row[r_word]; } Quote Link to comment Share on other sites More sharing options...
dk4210 Posted March 10, 2011 Author Share Posted March 10, 2011 You are a genius.. That worked great! Quote Link to comment Share on other sites More sharing options...
stawkerm0h Posted March 10, 2011 Share Posted March 10, 2011 what do this code do??please explain $wordlist = "sh%t:cr*p|dang:d*ng|shoot:sh**t"; and also this one?? please explain too $seperate_text = "|"; $entry_seperate_text = ":"; while($row = mysql_fetch_array($search_for_bad_words)) { $wordlist = $wordlist.$seperate_text.$row[word].$entry_seperate_text.$row[r_word]; } Quote Link to comment Share on other sites More sharing options...
dk4210 Posted March 10, 2011 Author Share Posted March 10, 2011 Hi stawkerm0h, This whole script is a filtering script when you need to filter out specific words when you have a form with text fields and textareas. This code here basically lists the words to filter and their replacement. Like the second one. Let's say the user enters the word "dang" it will be replaced by d*ng (It's separated by the $wordlist = "sh%t:cr*p|dang:d*ng|shoot:sh**t"; This code here does the same thing EXCEPT it queries the database for the words instead of having a static word list $seperate_text = "|"; $entry_seperate_text = ":"; while($row = mysql_fetch_array($search_for_bad_words)) { $wordlist = $wordlist.$seperate_text.$row[word].$entry_seperate_text.$row[r_word]; } Hope this helps! 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.