well one way is to use str_replace
<?
$text = $_POST['text'];
$text = str_replace("badword", "ba***rd", $text);
?>
another way this is if you want to be easilly able to add bad words is store them in a mysql database
<?
//mysql stuff
$query = "select * from badwords";
$result = mysql_query($query);
while($row = mysql_fetch_object($result)){
$text = str_replace("$row->badword", "$row->replaced", $text);
}
?>
hope it helps.