Home arrow PHP arrow Page 5 - Search This!

Performing the Search - PHP

Add search capabilities to your site using the popular open source tools PHP3 and ht://Dig.

TABLE OF CONTENTS:
  1. Search This!
  2. Configuring ht://Dig
  3. Indexing the Site
  4. Building the Search Page
  5. Performing the Search
  6. Displaying the Results
By: Colin Viebrock
Rating: starstarstarstarstar / 24
March 15, 1999

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: