Miscellaneous Code

  Home arrow Miscellaneous Code arrow SmartText
MISCELLANEOUS CODE

SmartText
By: Codewalkers
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2003-04-04

    Table of Contents:

     
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement
    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 out

    By : 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

    blog comments powered by Disqus

    MISCELLANEOUS CODE ARTICLES

    - Creating a Web Page Controller with the HMVC...
    - Coding Controllers and Views for the HMVC De...
    - A Sample Web Application with the HMVC Desig...
    - Adding a Class to Parse Views to an HMVC Des...
    - Building a Model Class for the HMVC Design P...
    - Filtering Input Data and Generating HTML For...
    - The HMVC Design Pattern: Working with MySQL ...
    - Dispatching Requests to MVC Triads with the ...
    - Implementing the Hierarchical Model-View-Con...
    - A Web App Based on a Model for the CodeIgnit...
    - Completing a Model for the CodeIgniter PHP F...
    - Validating Input Data with the CodeIgniter P...
    - Deleting Database Records with the CodeIgnit...
    - Inserting Database Records with a CodeIgnite...
    - Fetching Database Rows with a Model for the ...


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 3 - Follow our Sitemap