0 members and 7,720 guests
No Members online

» Site Navigation
» Stats
Members: 35,442
Threads: 103,075
Posts: 826,688
Top Poster: cc.RadillacVIII (7,429)
|
-
A simple PHP tutorial which blocks out whatever word that you would like it to block out.
text.htm
Code:
<html>
<head>
<title>Simple Badword Filter</title>
</head>
<body>
<font face='verdana' size='2'>
<h1>Simple Badword Filter</h1>
<form method='post' action='testit.php'>
<textarea name='text' rows='10' cols='20'></textarea>
<input type='submit' value='Test It'>
</form>
</font>
</body>
</html>
testit.php
Code:
<?php
/* Check.php */
function check() /* Establishes the function check */
{
global $text; /* Gets All Variables */
//To Add New Words, Just Copy One Line From Below And Paste It Below The Third Line. Just Replace the first word in quotes with the word you would like, and the second word in quotes to what you would like to change it to.//
$text = str_replace("hey","****",$text); /* Replaces the word "hey" into "****" */
$text = str_replace("pie","****",$text);
$text = str_replace("php","***",$text);
echo $text;
}
return check(); /* Returns the function check() */
?>
Example Here
Brought To You By PHPMini
-
That could be very useful for renaming mistypings and such, thanks for your tutorial!
-
I would code it differently, since replacing each word seperately will be slower than my code here.. (Actually i would use mysql, but i can't be bothered here)
Code:
<?php
function check($string)
{
$replace = array();
$with = array();
$replace[] = "hey";
$with[] = "***";
$replace[] = "test";
$with[] = "monkey";
/* just keep adding em */
return str_replace($replace, $with, $string);
}
echo check("hey, i'm testing"); /* will return ***, i'm monkeying */
?>
-
This is very useful. I am eventually going to run my own site in about 1 year I should be ready. I don't want to just start a site with out having everything I need. So yea. Good Tutorial.
-
i have made the bad word filter for filtering my emails.
I would like to know how to make certain email ids avoid this word filter I mean some of my very close friends are blocked by this word filter How to allow them sending mails avoiding this word filter ?
How to code it ?
-
Hmm you certainly now alot /scarasm
example
PHP Code:
<?php
function check($string) { $replace = array(); $with = array();
$replace[] = "hey"; $with[] = "***";
$replace[] = "test"; $with[] = "monkey";
/* just keep adding em */
return str_replace($replace, $with, $string); } echo check("hey, i'm testing"); /* will return ***, i'm monkeying */ ?>
now lets use that function...
Testing, Popping in to say hey and good test. // Output: monkeying in to say *** and good monkey.
see what i mean? it replaces anything with the letter's joined up i had this problem on a mates forums e.g. class would show cllove as the word ass..
Karlos
-
Nice way to bump a thread from 2005.
-
Tbh i don't care when a thread was started, i like to point out the point and flaws...
And Hello Apathy
-
Help
Is it possible to put all the words in a txt file and just matching it to the message(whereby if a badword is detected it just echo a message?) instead of replacing the words? Urgent reply needed
-
Actually the most effective way would be to use general word to replace several words. And yes a text file can be used.
PHP Code:
<?php $bad_words = file("your bad words file.txt"); function CensorBadWords ($text, $censor) { for($i=0; $i < count($bad_words); $i++) { $text = str_replace($bad_words[$i], $censor, $text); } return $text; } echo CensorBadWords("Your Potty Mouth Here", "******"); ?>
this would replace bad words with ****** in your badwords file it would need to be layed out like this
Code:
word one
word two
word three
Similar Threads
-
By Ravon in forum Sigs & Manips
Replies: 9
Last Post: 10-30-2005, 06:59 AM
-
By DragonsRage in forum Sigs & Manips
Replies: 6
Last Post: 06-21-2005, 01:05 PM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|