Publishing System Settings Logout Login Register
Censor Submitted Text
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on June 28th, 2007
750 views
PHP Coding
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
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Herbert

This author is too busy writing tutorials instead of writing a personal profile!
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top