PHP Form.net
Free PHP Forms and Scripts
PHP Scripts
LinkBase 1.1.Comments 1.1.
Meta Tags Generator 1.1.
E-Cards 1.1.
Feedback Form with Captcha
Tell A Friend
Contact Us - PHP Form
HTML Button Generator
PopUp Window Code Generator
Site Recommendation
ShoutBox 1.1.
PHP Tutorials
Creating a CAPTCHA with PHPBad Word Filter with PHP
Sponsor
Links
JaRobot.comOWD :: 40070.org
www.metaTageEn.com
PHP Resource Index
Pixel2Life.com

Creating a basic bad word filter in PHP - PHP tutorial
This tutorial will show you how to create a basic bad word filter in PHP.Code:
<?php
$text = $_POST['text'];
if(isset($_POST['submit']))
{
//Must be at least 3 characters and not more than 20
//The field must be at least 3 characters long
if (strlen($text) < 3) {
echo "<center>The field must be at least 3 characters long:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//The field cannot contain more than 20 characters
elseif (strlen($text) > 20) {
echo "<center>The field cannot contain more than 20 characters:
<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
// May not start with a dot
elseif (ereg("^\.",$text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain a <
elseif (ereg("\<", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain a [
elseif (ereg("\[", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain a ]
elseif (ereg("\]", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain "viagra"
elseif (ereg("\viagra", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain "online"
elseif (ereg("\online", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain a @
elseif (ereg("\@", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain "online"
elseif (ereg("\online", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
//Text cannot contain a %
elseif (ereg("\%", $text)) {
echo "<center>Invalid Characters:<a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
echo $text;
}else{
?>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="text" name="text"><br>
<input type="submit" name="submit" value="demo"><br>
</form>
<?php
}
?>
discuss this topic to forum
01/01/08
Name: Stijn Date: 2008-11-19 10:55:57
Thanks, very useful!
Name: admin Date: 2008-10-05 13:15:00
Thank You, Paul
Name: Sava Date: 2008-09-23 00:01:37
Very nice and useful!
HTML Not Allowed.