This ought to ssolve that problem, just add to the $punc_array to add more puncuation you want left out.
Code:
<?
$censor_array = array("cat", "dog", "bee");
$punc_array = array(".", ",", "?");
function censor_text($text) {
global $censor_array, $punc_array;
$data = explode(" ", $text);
for($i=0;$i<count($data);$i++) {
if (in_array(strtolower(ereg_replace("[\.,\?]", "", $data[$i])), $censor_array)) {
for($j=0;$j<strlen($data[$i]);$j++) {
if(in_array(substr($data[$i],$j,1), $punc_array)) {
$tmp .= substr($data[$i],$j,1);
}
else {
$tmp .= "-";
}
}
$data[$i] = $tmp;
unset($tmp);
}
}
return implode(" ", $data);
}
print censor_text("This Cat lives in a catalog with his pal the Dog.");
?>
Bookmarks