HomeSunday, June 24, 2018, 01:33:20
4

Creating a basic bad word filter in PHP

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

How to check checkbox checked

Checking if checkbox is checked with jQuery

Inserting form data in MySql table

Inserting form data in MySql table with PHP

Bookmark Script

Allow your users to easily bookmark your site, by clicking on a link on the page.

Preventing multiple form submissions

Preventing multiple form submissions

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

PHP Str_replace - PHP Tutorial

This function returns a string or an array with all occurrences of search in subject replaced with the given replace value.

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.

Send This Link PHP Script

A popup form which allows your visitors to send a referral link from your site. It features admin notification and HTML output.

PHP Date Examples

Returns a string formatted according to the given format string using the given integer timestamp or the current time if no timestamp is given.

PHP filesize

The filesize function returns the size of the specified file.
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.