function link_to_dict($myarticle){ /* Take the text block and convert it into seperate variables */ $newcontent = ""; $articles = explode(" ",$myarticle); foreach($articles as $item){ $cont = true;
/* If $item is a monetary amount or has numbers or hyphens or underscores, disregard */ if (preg_match("(^\\$|[0-9]|-|_)",$item)){ $cont = false; }
/* If there is a "." "," "?" "!" in $item, get rid of it before we do the lookup */ if (preg_match("/\./",$item)){ $srch_item = preg_replace("(\\.|\\,|\\!|\\?)","",$item); } else { $srch_item = $item; }
/* If $item is longer than 5 letters, provide a link to give the dictionary */ if (strlen($item) > 4 && $cont == true){ $newcontent .= "<a href=\"#\" onClick=\"window.open('./mydict.php?searchfor=$srch_item','Results','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,width=600,height=400')\">$item</a> "; } else { $newcontent .= "$item "; } } return $newcontent; }
/* Textbox for conversion */ $page .= "<textarea name=\"convertme\" rows=10 cols=100 /></textarea>\n<input type=\"submit\" />\n"; $page .= "</form>\n"; $page .= "<pre> Paste a selection of text into the text area above and click Submit</pre>\n";
/* Seperate the page, print the output if we have POSTed info */ $page .= "<hr>\n\n"; $page .= "<table width=\"80%\">\n\t<tr>\n\t\t<td>\n";
/* Grab POSTed text and pass it to the function */ $textblock = $_POST['convertme']; if ($textblock) $page .= nl2br(link_to_dict($textblock)); /* Pass text string to function, add <br>'s in linebreaks * so we keep everything on one page. */
/* Creates a new instance of Net_Dict */ $myDict = new Net_Dict; $myDict->connect();
/* Search for keyword and print output to browser */ $defs = $myDict->define($keyword); foreach ($defs as $def) { echo "<pre>" . $def['definition'] . "</pre>"; }
/* Close up instance */ $myDict->quit();
?>
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.