Ad block is installed and active. Please support us by disabling it.
HomeThursday, September 21, 2017, 03:26:55
3

Creating a basic bad word filter in PHP

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

Addslashes - Stripslashes

addslashes — quote string with slashes, stripslashes — un-quotes a quoted string

Smarty - Create dynamic Web Pages with PHP & MySQL

Creating Dynamic Web Pages Using Smarty and MySQL - Requirement(s): PHP Server, MySQL

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.

Adodb Recordcount Example

RecordCount returns the number of rows in the record set.

Preg_Match - PHP Email Validation

Validate email with preg_match in php

Convert pdf to image - mpdf

Convert pdf file to jpg with php and mpdf

Sending HTML Email With Images - PHP Tutorial

Sending HTML Email With Images - Upload Image with PHP - Creating Dynamic Webpages Using PHP and MySQL - Select, Delete, Update..

ShoutBox 1.1. PHP Script

ShoutBox allows your users to post short messages on your site. The script is lightweight and very easy to install and use.

Timed Redirect JavaScript

Timed redirect javaScript/PHP example
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.