This php function takes a list of words you define and censors them. In the example you have an array of banned words and a $replace variable that is used as a replacement of the censored words.
By using eregi_replace function we can check every word in the array and replace it with the desired, proper code.
-
<?php
-
-
$banned = array("visit", "http://", "www.", ".com");
-
$replace = '<span style="color:red; font-style: italic;">×××</span>';
-
-
function censor($content) {
-
global $banned, $replace;
-
foreach($banned as $words) {
-
$content= eregi_replace($words, $replace, $content);
-
}
-
return $content;
-
}
-
-
echo censor("Visit us at http://www.phpjunk.com");
-
//or if you store data into a variable:
-
echo censor($data);
-
?>