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!
Get all your badwords and put them in memory. It'll always be more efficient to look for the badwords in the text, that looking for every word in the text, into the database.
Good luck!
$qry = "SELECT id, word FROM badwords WHERE (word = '{$input}' OR word LIKE '%{$input}%'";
精彩评论