Ad block is installed and active. Please support us by disabling it.
HomeSaturday, January 20, 2018, 16:54:31
4

Creating a basic bad word filter in PHP

Tuesday, February 10, 15, 00:51:30, 3 Yaers Ago Via wain, Hits: 3703
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

Math Captcha V6

PHP Math Captcha Image Version 6

GuestBook PHP Script

Allow visitors to leave messages on your site. It features easy install, admin notification, and control panel to remove unwanted entries.

RSS, MySQL & Smarty

Smarty > Publishing MySQL Data in RSS 2.0

MySQL Basic Functions

MySQL Basic Functions - select, delete, update..

Show / Hide Div with CSS

CSS Display and Visibility:The visibility property specifies whether or not an element is visible.

How to check checkbox checked

Checking if checkbox is checked with jQuery

Preventing multiple form submissions

Preventing multiple form submissions

PHPBB3 Shoutbox

Vesion: 1.1. Released: 08/08/10, Licence GNU, Price: Free

PHP Fwrite : fwrite

php write to file - how to write data to a file using the php frwite function

Comments 1.1. :: PHP Script

This script allows your visitors to add comments to any single page on your web site.
About Author

wain

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