I was looking for a way to incorporate PHP code within HTDig results, and I
also had trouble with the DevShed tutorial - I came up with my own
workaround, admittedly a little bit clunky.  This is what my script does:

1. Intercept the query data from the HTML search form (Set the search form
method to GET and the action to the PHP script)
2. In PHP, use fopen() to send $QUERY_STRING to htsearch
3. Write the data returned from htsearch into a temporary file
4. use the include() statement to include (and parse as PHP) the temporary
file
5. destroy the temporary file.

This way you can include PHP code within your header/footer/long
results/short results template files.  I can't say how well this solution
would work on a site that gets heavily searched; performance probably isn't
spectacular with the addition writing to and reading from a temporary file
for every single search, so use it at your own risk, YMMV, caveat emptor,
etc.  Here's the script:

<?
//This script is a workaround  that allows for the inclusion of PHP code
within HTdig results.

//HTDig returns its results with Content-Type header of 'text/html', which
prevents the use of embedded PHP code; the tags don't get parsed.
//This script intercepts the query string sent from the standard HTDig form,
and opens an 'fread' connection to HTDig using this query information.
//The HTDig results are then stored in a temporary file.
//This temporary file is then included in this script, and finally any PHP
code within HTDig's output gets parsed.
//Once read, the temporary file is removed.
//
//Written by Andy Chase ([EMAIL PROTECTED])

//IMPORTANT:  You must escape Any PHP variables you use within HTDig's
template files, otherwise HTDig will try to
//*********   parse them as its own variables; this will probably confuse
both PHP and HTDig.
//            Example:  Instead of '$date = date("m/d/Y")', use '\$date =
date("m/d/Y")'


//Point the HTDig search form at this script using the GET method.

$fh = fopen("http://$SERVER_NAME/cgi-bin/htsearch?$QUERY_STRING","r";);
//Open a file pointer to the actual HTDig CGI-BIN and append query string.

$results=fread($fh,1048576);    //Read up to the first 1024k of the HTDig
results (or EOF, whichever comes first).
                                //The results probably won't ever be as large as 
1024k; this number is
set as an arbitrary limit.

$results=preg_replace("/\/cgi-bin\/htsearch/","/htdig/bin/search.php",$resul
ts);  //redirect any references to the htsearch CGI-BIN in the search
results to this script

fclose($fh);

$ts = date("U");
$tf = fopen("/tmp/htdig$ts.tmp","w"); //Create unique temporary file(using
timestamp) in the /tmp directory to store results

fwrite($tf,$results);

fclose($tf);

include("/tmp/htdig$ts.tmp");   //include the temporary file; PHP is now
parsed

unlink("/tmp/htdig$ts.tmp");    //Remove the temporary file.


?>

> From: "Dan Langille" <[EMAIL PROTECTED]>
> Organization: novice in training
> To: [EMAIL PROTECTED]
> Date: Sun, 17 Jun 2001 18:39:40 -0400
> Reply-to: [EMAIL PROTECTED]
> Subject: [htdig] completing a php wrapper
>
> I'm in the process of using the PHP wrapper guide as found at:
>
> http://htdig.org/contrib/guides.html which points to
> http://www.devshed.com/Server_Side/PHP/search/
>
> The DevShed article is good as it's shown me the way to get started.
> But there are a few little niggles which are preventing me from
> finishing.
> I'm posting this message as a request for clues and in the hope that
> someone will say "look here, it's already been done...".

------------------------------------------------------------------
|  Andy Chase - Web Programmer  |  Valley Presbyterian Hospital  |
|  [EMAIL PROTECTED]  |  15107 Vanowen Street          |
|  818.782.6600 x 5141          |  Van Nuys, CA  91405-4597      |
------------------------------------------------------------------



_______________________________________________
htdig-general mailing list <[EMAIL PROTECTED]>
To unsubscribe, send a message to <[EMAIL PROTECTED]> with a 
subject of unsubscribe
FAQ: http://htdig.sourceforge.net/FAQ.html

Reply via email to