OK so this is what I came up with, but doesn't work. Sorry about this, I am fairly new to PHP and not sure if I'm doing this right. Here is the code I wrote (with your help of course)
//Automatically find words that are in dictionary and replace them with links in the form input
function DictEncode($forminput){
$forminput = preg_replace("/[[:alnum:]|[:space:]]/","",$forminput);
$wordarray = explode(" ",$forminput);
//Connect to database and find words
$db=mysql_connect("localhost","username","password");
mysql_select_db("databasename",$db);
$query = "SELECT * FROM dict WHERE word IN ('".implode("', '", $wordarray)."');";
$result = mysql_query($query);
$replacedict= array("<A HREF=home.php?m_column_id=php_dict/result.php?word=$result>$result</A>");
return str_replace(stripslashes($result),stripslashes($replacedict),stripslashes($forminput) );
}