Ad block is installed and active. Please support us by disabling it.
HomeWednesday, April 25, 2018, 08:54:57
4

Creating a basic bad word filter in PHP

Tuesday, February 10, 15, 00:51:30, 3 Yaers Ago Via wain, Hits: 6375
This tutorial will show you how to create a basic bad word filter in PHP
Code:
<?php
if(isset($_POST['submit']))
{
$data = $_POST['data'];
$data2 = $_POST['data2'];
$data3 = $_POST['data3'];
$name=array($data,$data2,$data3);
foreach ($name as $name)
{
if (preg_match("/%/",$name)) {
echo "<center>Invalid Characters: % <a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (preg_match("/</",$name)) {
echo "<center>Invalid Characters: < <a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
if (preg_match("/xxx/",$name)) {
echo "<center>Invalid Characters: xxx <a href=\"javascript:history.go(-1)\">Go Back</a></center>";
Die();
}
}
echo $data;
echo"<br />";
echo $data2;
echo"<br />";
echo $data3;
echo"<br />";
}else{
?>
<form action="index.php" method="post">
<input type="text" name="data"><br>
<input type="text" name="data2"><br>
<input type="text" name="data3"><br>
<input type="submit" name="submit" value="demo"><br>
</form>
<?php
}
?>

Michael Wednesday, May 4, 2011, 20:15:00

Note that the ereg() function has been deprecated as of PHP 5.3.0 and removed as of PHP 6.0.0.
Relying on this feature is highly discouraged.
preg_match(), which uses a Perl-compatible regular expression syntax,
is often a faster alternative to ereg().

if(isset($_POST[\'submit\']))
{
$data = $_POST[\'data\'];
$data2 = $_POST[\'data2\'];
$data3 = $_POST[\'data3\'];
$name=array($data,$data2,$data3);
foreach ($name as $name)
{
if (preg_match(\"/%/\",$name)) {
echo \"

Invalid Characters: % Go Back
\";
Die();
}
if (preg_match(\"/ echo \"
Invalid Characters: < Go Back
\";
Die();
}
if (preg_match(\"/xxx/\",$name)) {
echo \"
Invalid Characters: xxx Go Back
\";
Die();
}
}
echo $data;
echo\"
\";
echo $data2;
echo\"
\";
echo $data3;
echo\"
\";
}else{
?>










}
?>

richi Thursday, May 19, 2011, 23:07:34

@Michael its very nice.

Sign In

Sponsor

A website like http://www.stlouisinsulation.com will provide you with the highest quality in the industry.

Easy to use PHP/MySQL recipes script for anyone who wants to create and maintain Recipes website.

Related

Creating a Math CAPTCHA with PHP - PHP Tutorial

This tutorial will show you how to create a form with Math Captcha.

Jquery - Formatting International Phone Numbers

How to format international telephone numbers with jquery

PHP Links Script 1.1.

This script allows you to manage your links using a MySQL database. It features easy install, user submission, and an admin panel to add, edit and remove categories and links. The script is easy to customize to suit your needs.

PHP explode

Explode — Split a string by string.

Contact Us 2.0. with HTML Page and Pop Up Frame

This is the same Contact Us 2.0. that is in this forum, But I have added more options to this script and a html page with a very nice pop Up frame that DONT get block by any pop Up software. Many websites use this type of script to bypass the blocking…

Imageline

Draws a line between the two given points.

PHP Form Validation

PHP form validation :: PHP tutorial, requirement(s): PHP Server

Block Visitors From Specific IP Address

Learn How To Restrict Users From Different IP Addresses.

Jquery PHP Contact Form

This script allows your visitors to send you an email directly from your website.

Creating a CAPTCHA with PHP with imagecreate

This tutorial will show you how to create a form with Captcha, Requirement(s): PHP Server, GD Graphics Library
About Author

wain

Date Registered: Sun, Feb 8, 15
Last Time Online: Sun, Mar 18, 18
So far has created 115 entries.
wain
This author has not yet filled in any details.