Better Solution for Filtering Bad Words in PHP

On December 19, 2009, in Mysql, PHP, Tips, Tricks, by admin

I was searching for filtering Bad Words from my site……

I have visited so many links on google but…. :(

Here is my simple logic for filtering Bad Words from site or any search engine

First you have to make a txt file “badwords.txt” or you can search from google

Google Keyword: badwords + filetype:txt

Copy “badwords.txt” to your site and use below code for removing these words from site…..

<?php

// here file_get_contents() used for getting $badwords as a string

$badwords = strtolower(file_get_contents(“badwords.txt”));

// here $q is string used for checking against badwords

$pos = strpos($badwords, strtolower($q));

if ($pos !== false)
{

if(strstr($badwords, strtolower($q)) || strchr($badwords, strtolower($q)))
die(‘Website has blocked unwanted contents…. please try for legal keywords!’);
}

?>

Enjoy with phpsolutions.co.in :)

2 Responses to Better Solution for Filtering Bad Words in PHP

  1. Anonymous says:

    Thanks for sharing superb informations. Your websiteis so cool.I’m thankful for the details that you’ve within this blog. It reveals how nicely someone perceives this subject. Bookmarked this web site, will happen backfor extra articles. You, my pal, ROCK! I discovered simply the info I already searched all over the place and just couldn?t come across. Such a ideal website. I love this web site whilst your website is without a doubt among my new favorite ones.I like this amazing site given and contains given me a dedication achievement for a lot of purpose, so thanks

  2. Anonymous says:

    Kudos for posting a real useful weblog. Your website isn’t only informative but additionally very artistic too. There are typically very couple of people who can write low number of simple articles that creatively. Continue the excellent writing !!

Leave a Reply