PDA

View Full Version : [PHP] Word Filter



kickerbat
02-01-2008, 02:27 PM
hi i need a word filter script that will include a .php / .txt file with badwords and replace them with Bobba or *****

Please Post Back:eusa_danc

kickerbat
02-01-2008, 02:46 PM
$bad_words = explode('|', 'badword1|badword2|badword3|etc|etc');
foreach ($bad_words as $naughty)
{
$comments = eregi_replace($naughty, "bobba", $comments);
}



got a script posted if any body wanted

say a bad word = "bobba"

lolwut
04-01-2008, 09:11 PM
<?php

function filter($var){

$badwords[0] = '/badword1/';
$badwords[1] = '/badword2/';
$badwords[2] = '/badword3/';
$badwords[3] = '/badword4/';

preg_replace($badwords, "bobba", $var);

return $var;

}

?>
Use like:
$var = filter($var);
Post if it doesn't work.

Ini
04-01-2008, 09:46 PM
SQL:



CREATE TABLE `filter` (
`id` int(11) NOT NULL auto_increment,
`word` varchar(50) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;


filter.php


<?php
//include your database connection
include("YOURCONNECTIONFILE");
//sets a php functions
function filter($content){
//selects rows from your database
$filter = mysql_query("SELECT * FROM `filter`");
//loops all the rows out
while($wfilt = mysql_fetch_array($filter))
{
//finds the string and replaces it with the consored image
$content = str_replace ("$wfilt[word]", "Bobba", $content);
}
//returns the string after being filtered
return $content;
}
?>


at the top of your page add



include("filter.php");

Want to hide these adverts? Register an account for free!