How To Call Only Part of PHP Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zoomology
Forum Newbie
Posts: 3
Joined: Sun Jul 22, 2007 7:42 am

How To Call Only Part of PHP Script

Post by zoomology »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello,

I'm hoping someone can help resolve my problem, or at least tell me whether it's possible or not so I can elect another option.

[b]OBJECTIVE[/b]
I want to call a particular function of a PHP script, a queried term, and print it to the <title> and/or <h1> tag of a document on the fly for a given search.

[b]THE SCRIPT[/b]
The script in question is the Zoom search engine (PHP install). The script is called and the search results are created by virtue of an include [color=red]<?php include("search.php"); ?>[/color] which is inserted into my website's .php template file. 

[b]PROBLEM[/b]
Unlike most off-the-shelf site search scripts, Zoom doesn't generate page titles at top of the page for a particular query. Further, all requests (so far) to Zoom's support staff have been ignored.

[b]ESTABLISHED[/b]
I have been successful inserting the query term using [color=blue]<?php print "$query"; ?>[/color] however, it will only work when placed below the point of where the script include is added to the template, seemingly since the script's code is called (and search results generated) between the template's header and footer.

[b]SUMMARY[/b]
It may be possible to use [color=blue]<?php print "$query"; ?>[/color] to generate the searched term in various other areas on the page, however I don't have the requisite skills to code the template to facilitate the task. I theorize that it may possible to do this using code I'm unfamiliar with -- such as a type of "include() once" placed at top of the template's code.

Could a language construct such as echo(), print(), include(), or require() be added to beginning of the template file to call the $query so as to print to placeholders within the page titles and heading tags?

Code: Select all

<?php

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php print("$query"); ?></title>

<h1><?php print("$query"); ?></h1>
HOST SERVER
Apache/1.3.37
PHP/4.3.10


...any help appreciated. Thanks.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

In short, no you can't use $query until the software has created that variable. Do you have the code which creates $query?
zoomology
Forum Newbie
Posts: 3
Joined: Sun Jul 22, 2007 7:42 am

Post by zoomology »

d11wtq wrote:In short, no you can't use $query until the software has created that variable. Do you have the code which creates $query?
Hmm, that's distressing news.

Yes I do have the code - but it's 2,114 lines of PHP. If you don't mind, I'll take the liberty of sending it to you.

.
zoomology
Forum Newbie
Posts: 3
Joined: Sun Jul 22, 2007 7:42 am

The fix is in...

Post by zoomology »

Since I really like Zoom's convenience, functions and easy installation, I continued to pursue a solution; a fella on another forum provided the mods and code tweaks I needed. I was able to provide enough information for him to figure it out quickly. Below is the fix for anyone else wanting the same results.

The following was added to the .htaccess file. Note that mywebsite.net is changed to my own domain and support.php is my template filename. Adding the mod_rewrite rules allow me to link to a specific keyword search that uses a more search engine friendly URL. The + sign was left in place so as not to interfere with Zoom's other algorithms.

example: <a href="/asbestos+dust.php">asbestos dust</a>

Code: Select all

<FilesMatch "\.(php|html?)$"> 
   php_value zlib.output_compression 4096 
</FilesMatch> 

<Files /> 
   ForceType application/x-httpd-php 
</Files> 

php_flag allow_url_fopen on 
php_value allow_call_time_pass_reference 1 

Options +FollowSymLinks 
ErrorDocument 404 http://www.mywebsite.net 

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\.mywebsite\.net [NC] 
RewriteRule ^(.*)$ http://www.mywebsite.net/$1 [R=301,L] 

RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteRule ^([^/]+)\.php$ /support.php?zoom_query=$1 [L]

The below was added inside the <title> and <h1> tags to generate the searched term in those areas of my template.

Code: Select all

<title><?php echo htmlentities($_GET['zoom_query'], ENT_QUOTES); ?></title>

<h1><?php echo htmlentities($_GET['zoom_query'], ENT_QUOTES); ?></h1>
In any event, everything's working okay now and I'm a happy camper.

.
Post Reply