Using PHP 4.3.x or do you have
PEAR installed. By adding the
Net_Dict package, you can provide links to the dictionary.
Try it outBy : bigphish
<!-- dictlink.php
<?php
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;
}
/* Start page content */
$page = "";
$page .= "<html>\n<head>\n<title>Text links</title>\n</head>\n\n";
$page .= "<body>\n";
$page .= "<form action=\"$PHP_SELF\" method=\"POST\">\n";
/* 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.
*/
/* PHinish off page content */
$page .= "\t\t</td>\n\t</tr>\n</table>\n";
$page .= "</body>\n";
$page .= "</html>\n\n";
/* Print to browser */
echo $page;
?>
<!-----------------------------------
<!-----------------------------------
<!-----------------------------------
<!-- mydict.php
<?php
require_once '/usr/local/lib/php/Net/Dict.php';
$keyword = $_GET['searchfor'];
/* 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. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications to provide services to customers, employees and partners, these complex applications become more difficult to secure. Although traditional security solutions protect Internet infrastructure layers, they do not guard against HTTP and HTML attacks. Many organizations that conduct security testing still deploy applications that allow attackers to manipulate their logic and wreak havoc on their business. To mitigate this risk, development and delivery teams must address Web application security throughout the lifecycle, addressing the many layers detailed in this paper. FREE! Go There Now!
|
|
|
|
CakePHP is a stable production-ready, rapid-development aid for building Web sites in PHP. This "Cook up Web sites fast with CakePHP" series shows you how to build an online product catalog using CakePHP. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of WebSphere Extended Deployment Compute Grid, which lets you schedule, execute, and monitor batch jobs. Because online transaction processing and batch jobs execute simultaneously on the same server resources, you can avoid costly duplication of resources. Compute Grid supports job types of Java transactional batch, compute-intensive and a new type called "native execution", which enables non-Java workloads to run on distributed end points. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Join this webcast to discover the key requirements for successful change and release management. Learn how to extend your .NET environment to improve productivity and collaboration, and address core problems afflicting team development. In this webcast, we’ll review typical challenges faced by customers and how to resolve them with the IBM Rational Change and Release Management solution, including Rational ClearCase, Rational ClearQuest and Rational Build Forge. Replay is available for 9 months. FREE! Go There Now!
|
|
|
|
As businesses grow increasingly dependent upon Web applications, these complex entities grow more difficult to secure. Most companies equip their Web sites with firewalls, Secure Sockets Layer (SSL), and network and host security, but the majority of attacks are on applications themselves – and these technologies cannot prevent them. This paper explains what you can do to help protect your organization, and it discusses an approach for improving your organization’s Web application security. FREE! Go There Now!
|
|
|
|
The Eclipse community is constantly working to extend Eclipse's functionality. In this webcast, learn about some of the most important and feature-rich projects under development. From multi-language support to plug-in development, tune in to see what Eclipse is capable of now. FREE! Go There Now!
|
|
|
|
In this webcast, you'll get an introduction to the eXtreme Transaction Processing (XTP) features of WebSphere Extended Deployment and the common architectural traits required by XTP applications. See how WebSphere Extended Deployment's ObjectGrid feature provides a state-of-the-art infrastructure for hosting XTP applications. FREE! Go There Now!
|
|
|
|
WebSphere Process Server delivers a unique integration framework that simplifies existing IT resources. Often, as IT assets grow to support business demand, so too does their complexity and manageability. In this webcast, we’ll discuss how WebSphere Process Server helps deliver an SOA infrastructure that provides a common model to orchestrate, mediate, connect, map, and execute the underlying IT functions. Discover how WebSphere Process Server simplifies integration of business processes by leveraging existing IT assets as reusable services without the complexities of traditional integration methodologies. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |