I have a (dictionary)table (mySQL) with words and definitions, what I want is that when somebody was to Submit a form, I want it to check one of the fields in the form, with all the words in the "dictionary table", and if there is a match to automatically put HREF tags in the form input so that it will now have links to the word in the dictionary. So this is what I came up with so far with the help of others, but doesn't work. I am fairly new to PHP and not sure if I'm doing this right. Here is the code I wrote:
//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) );
}