programmingsite : code , tutorials and scripts
Navigation

home


ASP
ASP.net
C
C++
C#
PHP
Java
JavaScript
Powershell
VB.net

Visual Basic


Resources
code
tutorials
training

Ads
Products

 

 

Simple banned words filter





Simple banned words filter

A useful little example which stores a list of banned words in a text file , we then search a string for the banned words and then edit them with the pattern. You could change the pattern at any time by changing the ****** .

We also display a drawback which shows how an innocent phrase can contain the banned words and would be filtered


<?php
function censored($message)
{
//the file with the banned words
$fp = fopen("banned.txt","r");
while($word = fgets($fp,10000))
{
//replace words
$message = ereg_replace(trim($word),"******",$message);
}
return $message;
}
?>

How to use this function


<?php
//our phrases
$msg = "This example is a load of shit";
$msg1 = "I like shitake mushrooms";
//display the censored version
echo censored($msg);
echo "<br>";
//this shaws a drawback of this and most other
//bad words filter , if the banned word appears in ANY WORD
//this is filtered meaning innocent words like shitake
echo censored($msg1);
?>



In action

This example is a load of ******
I like ******ake mushrooms





Products
500 Java Tips E-book
PHP editor
PERL editor
Beginning Java
Beginning Visual Basic
Learn VB.net
Learn VB 6
VB and databases
ASP image library
C++ builder programming
C++ fundamentals
Asp Studio 2005
Xtra PHP
Online PHP Script Encoder
Comparison

Links
Make money selling software
Uk shopping
UK price comparison
US price comparison
free articles
free stuff
Gambling resources
Software directory
XBox cheats and more
Sexy free wallpapers
Hosting resources
Nintendo Wii info
Beginners PHP
Health and fitness
Domain names
Dating site
Nintendo DS resources
Dropshippers
Maxi directory
Perfume and fragrances
PC shopping, tips and info
Magazine superstore

Ads