Hi Rob, thanks for your reply. Here is what I have so far with your help, but not sure if I'm doing this right or not. I get an error "Fatal error: Call to a member function on a non-object in...." Think it was something to do with what you have as "id", not sure what that is, I thought it was the fields in the db, but I renamed it to my field names and still didn't work. Maybe I will need you entire class, cause I am not sure if I'm doing it right. Thanks for your help again... Here is what I wrote.
//Start of function that 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","name","pass");
mysql_select_db("database",$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
//Puts content from mySQL into an array called found
while ($found[] = mysql_fetch_array($myresult)) {
// nothing!
}
mysql_free_result($myresult);
for ($i = 0; $i < count($found); $i++) {
$replace = $this->expandMacro("id",
$this->defs[strtoupper($found[$i])],
$this->link_start);
$def_name = strtoupper($found[$i])."-def";
$replace = $this->expandMacro("def",
addslashes(
$this->stripPunct(stripslashes(
$this->defs[$def_name]), "\"")),
$replace);
$caption = "Definition: $found[$i]";
$replace = $this->expandMacro("caption",
$caption,
$replace);
$replace .= $found[$i] . $this->link_end;
$start = strpos($txt, $found[$i], $offset);
$end = strlen($found[$i]);
$offset = $start + strlen($replace);
$txt = substr_replace($txt, $replace, $start, $end);
// }