Here is a function I wrote with the help of others on this board. I am fairly new to PHP but I got it working. It uses OverLib to do a nice rollover definition.
//Automatically finds words that are in the dictionary and replaces them with links in the form input
function DictEncode($forminput){
//Take form input and convert it into an array of words
$formwords = preg_replace("/[[:alnum:]|[:space:]]/","",$forminput);
$wordarray = explode(" ",$formwords);
//Connect to database and find words in the dictionary that match words in the above array
$db=mysql_connect("localhost","db","password");
mysql_select_db("mydb",$db);
$query = "SELECT * FROM dict WHERE word IN ('".implode("', '", $wordarray)."');";
$myresult = mysql_query($query);
//Go through the results of the word matching and change the word into a link and resave it as the new form input
while ($row = mysql_fetch_array($myresult)) {
$origword = " ".$row["word"];
$theword = "/".$row["word"]."/";
$worddef = $row["definition"];
$caption = "Definition: ".$origword."";
$replace = "<a href=\"javascript:void(0);\" onMouseOver=\"overlib(\'$worddef\',WIDTH,214,HEIGHT,161, BACKGROUND, \'php_news/images/def_back.gif\',PADX,20,21,PADY,30,20,TEXTSIZE,1,CAPTION,\'$caption\')\" onMouseOut=\"nd()\">$origword</a>";
$forminput = nl2br(preg_replace($theword, $replace, $forminput));
}
return $forminput;
}
//End of function