PHP
  Home arrow PHP arrow Page 5 - Search This!
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Search This!
By: Colin Viebrock
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 24
    1999-03-15


    Table of Contents:
  • Search This!
  • Configuring ht://Dig
  • Indexing the Site
  • Building the Search Page
  • Performing the Search
  • Displaying the Results

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Search This! - Performing the Search
    ( Page 5 of 6 )

    ht://Dig is normally run as a CGI script ("normally" meaning "by everyone who doesn't use PHP3!"). To run the search program from PHP, you will need a file called htdig.sh which looks like this:


    #!/bin/sh HTBINDIR=/usr/local/htdocs/htdig/cgi-bin QUERY_STRING="$@" REQUEST_METHOD=GET export QUERY_STRING REQUEST_METHOD $HTBINDIR/htsearch

    Just change the value of HTBINDIR to whatever is appropriate for your setup (i.e. the path you picked for CGIBIN_DIR in the CONFIG file when you installed ht://Dig).

    I recommend putting this file in the search/ subdirectory as well, along with the template files. You also need to change file permissions so htdig.sh is executable by your web server.

    Next, we need to get PHP to talk to the search script. Finally, some PHP code! This is simply a matter of building the query string to pass to htdig.sh, executing the search, and parsing the results.

    So, in results.php3, we build the query string:


    <?php $HTSEARCH_PROG = "/www/summerworks/search/htdig.sh"; $words = EscapeShellCmd(UrlEncode($search)); $config = "sw98"; $format = "sw98"; $query = "config=$config&format=$format&words=$words"; ?>
    $HTSEARCH_PROG is the location of the htdig.sh program. $search is passed from the form, and is the list of words to search for. $config tells ht://Dig which .conf file to use, and $format tells it which template map to use from the .conf file.

    Then we run the search:


    <? $command="$HTSEARCH_PROG \"$query\""; exec($command,$result); ?>

    This puts the results of the search into the array $result, which PHP then parses to display the results.



     
     
    >>> More PHP Articles          >>> More By Colin Viebrock
     

       

    PHP ARTICLES

    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek