In this tutorial, you will learn how to create a censor script to block people from posting nasty content on your website.
First, you will start off with creating the database:
CREATE TABLE `censor` (
`id` int(11) NOT NULL auto_increment,
`bword` varchar(30) NOT NULL default '',
`gword` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;
This will create our table in the phpmyadmin database.
Next, I will supply u with two lines of code to add to the table to start off with:
INSERT INTO `censor` (`id`, `bword`, `gword`) VALUES (NULL, '69', '**'), (NULL, 'shit', '****');
INSERT INTO `censor` (`id`, `bword`, `gword`) VALUES (NULL, 'bitch', '*****');
INSERT INTO `censor` (`id`, `bword`, `gword`) VALUES (NULL, 'dick', '****');
Sorry for the words but this should help you out to begin with.
Lastly, you will create a page called 'censor.php' and then include this page within the page of which you want to use it on.
Include on a page:
<?php
include("censor.php");
?>
Page coding (with comments):
<?
include("config.php"); // includes the config page
function censor($content){ // creates the function
$content = nl2br(htmlspecialchars($content)); // creates that message that we put the censor in
$get1 = mysql_query("select * from censor"); // selects the words from the database
while($block = mysql_fetch_array($get1)) // creates while which repeats the codin making it check all works in the database
{
$content = str_replace($block[bword], $block[gword], $content); // replaces all bad words with good words tags
}
return nl2br($content);
}
?>
If this tut is not well commented or you are having problems with it, please contact me and i would be glad to help you. I also ensure you that this code was created by me and is not stolen from another website.
Enjoy!
~
Herbert DuBose III