RSS

Better Solution for Filtering Bad Words in PHP

19 Dec

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 svnlabs.com 🙂

Advertisements
 
Leave a comment

Posted by on December 19, 2009 in LAMP, MySQL, php, Tips, Tricks

 

Tags: , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: