Filter Bad Words Using PHP

bdword
Today we will learn how to filter bad words from text.

Many websites now filter out bad words from the comment fields and other places. We will go over how to filter out bad words from text using PHP.

The PHP

Here is an example of text containing “bad words” that we want filtered:

Create an array() of bad words to be filtered out of the text.

Create an array() of the replacement words. You can change the replacement words to whatever your liking is.

We use the PHP str_ireplace function to replace the bad words.

The whole PHP code

Text without the filter: You’re a badword. You big jerk. Darn! Text with the filter: You’re a @#$@#. You big j&*%. Da*@!

Conclusion

A simple way to filter out bad words.
I hope this helps you.

Barrett

Tagged with:

View all contributions by

Website: http://rrpowered.com

Related Articles

Advertisement

Stay connected with us

Add us on Google+

Follow us on Facebook

Follow us on Twitter

Get updates via RSS

Get email updates

FEEDBACK4

      1. Swathi Reddy
        4

        When you come across a new bad word, then you have to edit your php file and the array values. With this approach you might mess up with your code.

        With database, you just have to insert one record which is a clean way to do it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">