Emancipator
06-30-2005, 06:57 AM
I built a word filter for my website. What it does is basically automatically build links out of celebrity names in my news. Example link http://www.moviesonline.ca/movienews_4634.html You can see all the celeb names are auto-linked. I built the celeb pages so I dont need to tell it what to link to, they follow a pattern so the array is very simple and no work on my part building it.
I realize this is of next to no value to anyone else but I have dumbed it down a bit and you can use it for simple things like a "bad words" filter. Keep in mind the variables are movie related cause well my CMS is for a movie site :P
<?
$cast = 'Profanity, Profanity2, Profanity3'; // Naughty Sailor Talk
$st_str = trim($cast, ' '); // Trim white spaces
$strs = explode(',', $cast); // Explode into an array by delimiter
$content = 'What the Profanity is going on' //the text to apply it to.
for($i=0; $i<sizeof($strs); $i++)
{
$str = ' '.$strs[$i].' ';
$text = eregi_replace($str,' ',$text);
}
?>
The way I use this is $cast is my cast list, and I replace it not with *** but with links to the cast bio. The $content is actually the field where i store the main content of my news in my, MYSQL database. By dumbing it down I have made it so you can easily build a bad word filter. May not be the best way to do it, but it works like a charm on my site.
I realize this is of next to no value to anyone else but I have dumbed it down a bit and you can use it for simple things like a "bad words" filter. Keep in mind the variables are movie related cause well my CMS is for a movie site :P
<?
$cast = 'Profanity, Profanity2, Profanity3'; // Naughty Sailor Talk
$st_str = trim($cast, ' '); // Trim white spaces
$strs = explode(',', $cast); // Explode into an array by delimiter
$content = 'What the Profanity is going on' //the text to apply it to.
for($i=0; $i<sizeof($strs); $i++)
{
$str = ' '.$strs[$i].' ';
$text = eregi_replace($str,' ',$text);
}
?>
The way I use this is $cast is my cast list, and I replace it not with *** but with links to the cast bio. The $content is actually the field where i store the main content of my news in my, MYSQL database. By dumbing it down I have made it so you can easily build a bad word filter. May not be the best way to do it, but it works like a charm on my site.