So what do you have in the database, something like this?
+-------------------+
| bad | good |
+-------------------+
| ass | @$$ |
| etc. | so on |
+-------------------+
Best bet would be to use [man]str_ireplace/man I believe, like so:
$query = 'SELECT * FROM badwords';
$exec = mysql_query($query) or die('Error, MySQL said: ' . mysql_error());
while($result = mysql_fetch_assoc($exec)) $data = str_ireplace($result['bad'], $result['good'], $data);
echo $data; // $data should be safe now; no more bad words!
EDIT: Changed code to use str_ireplace() instead of str_replace() to make a more flexible search and replace.