Ad block is installed and active. Please support us by disabling it.
HomeSunday, November 19, 2017, 14:07:39
3

Creating a basic bad word filter in PHP

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

Stack Overflow Clone Script - Ja2BU

Open source question and answer script written in PHP, MySQL and jQuery. Main features are: SEO friendly url's, private message system, rating system, comments system.

Upload Image with PHP [Example2]

[Example2] Tutorial - How to upload and resize image with PHP

Getimagesize

Getimagesize function will determine the size of any given image file and return the dimensions along with the file type and a height/width text string to be used inside a normal HTML IMG tag and the correspondant HTTP content type.

Meta Tags Generator 1.1. PHP Script

This script will allow your visitors to create meta tags online.

Images In Textarea - CSS

Tutorial Images in Textarea

FeedBack Form with Captcha

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

Smarty Paginate Example - Smarty Pagination with PHP

Smarty Paginate Example, Smarty Pagination with PHP. SmartyPaginate: a class/plugin for data set pagination within the Smarty template environment

Link Base 1.1. - Free PHP Link Index Script

Manage your links using a MySQL database. Features easy install, user submission, and an admin panel to add, edit and remove categories and links.

PHP getdate

Returns an associative array containing the date information of the timestamp, or the current local time if no timestamp is given.

Captcha V1 - Free PHP Script

An anti-spam form protection image written in PHP, Version: 1.1.
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.