Jump to content

badwords from query


dk4210

Recommended Posts

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!

 

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/230155-badwords-from-query/
Share on other sites

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];
}

Link to comment
https://forums.phpfreaks.com/topic/230155-badwords-from-query/#findComment-1185352
Share on other sites

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];
}

Link to comment
https://forums.phpfreaks.com/topic/230155-badwords-from-query/#findComment-1185401
Share on other sites

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!

Link to comment
https://forums.phpfreaks.com/topic/230155-badwords-from-query/#findComment-1185509
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.