Jump to content

Recommended Posts

Part of my website needs to filter out offensive language from a string (message) in the site and replace swear words with *****.

 

I have one that works from a text file:

 

http://www.geekpedia.com/tutorial163_Foul-language-filter-in-PHP.html

 

but I need it to work for my MySQL database instead.

 

I have a lookup database table that contains the offensive words:

 

table: language_filter

fields: id, offensive_word

 

Anyone have any suggestions on how to get a MySQL language filter working?

Link to comment
https://forums.phpfreaks.com/topic/83797-language-filtering/
Share on other sites

  • 4 weeks later...

You might have to use 2 preg statements.

one to filter the words from the body of the subject. see preg_replace_callback

than use the callback function to test the individual words against a list of bad words, using preg_match.

if preg_match catches a bad word, it can return the [censored] tag or what have u, otherwise return the original word sent by preg_replace_callback.

 

thats if u want the flexibility of using regular expressions

Link to comment
https://forums.phpfreaks.com/topic/83797-language-filtering/#findComment-449636
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.