Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search Engine that searches <a> not files

Status
Not open for further replies.

badley

Technical User
Dec 20, 2002
75
GB
Hi All,

I have a product.php file in the root that relies on queries to direct it to specific directories/files within a product folder.

I've been looking for some code that searches pages for <a href> tags as I thought this might follow the folder structure but still keeping the root file as products.php.

I don't want the search facility to locate files in directories becuase i need it to pass the through the product.php page to include headers etc.

I'm not using a DB.

Any help would be greatly appreciated

Ed
 
not sure that i understand the question.

1. do you want to extract the value of all href attributes inside anchor tags on a page? if so preg_match_all is your friend. there was a post only a couple of days ago that feherke and I posted a method for doing this.

2. are you trying to rewrite links? if so, mod_rewrite is your friend.

if something else, could you have another go at explaining the question?
 
Point 1 seems to be almost correct.

The search facility would use those href to locate various files via queries and so-on. These files only have content no menu etc.

Another method would be to declare all queries in a txt file and using the fopen function search all the strings listed in that file.

Any clearer?

Thanks for the quick response jpadie
 
any clearer? not really. I can't see *why* you would want to do this.

but anyway - have a look back a few days and you'll find some good patterns for preg_match_all. combine the output with is_file and you should have what you need.
 
Sorry, my colleagues thought ?? too.

My current search retrieves the files within directories fine, but all these files & directories should be controlled by products.php, so they are missing the header, menu, css, script etc.

Currently, if I search for content within 1/index.php it would return just the index.php within the '1' folder. I want the search to read from href 'products.php?d=1' to the source and the content of that query, this will include the header menu from the products.php and the content from the index.php file folder 1 .

Code in products.php:

<?php

<?php include 'system/menu_1.php'; ?>

<?php include 'system/menu_2.php'; ?>

<?php include 'system/product_breadcrumb.php'; ?>

if ($d == 'home'){
include 'system/home.php';
}
elseif ($d == '1'){
include 'division/1/index.php';
}
elseif ($d == '2'){
include 'division/2/index.php';
}
elseif ($d == '3'){
include 'division/3/index.php';
}
elseif ($d == '4'){
include 'division/4/index.php';
}
elseif ($d == '5'){
include 'division/5/index.php';
}
elseif ($d == ''){
include 'system/home.php';
}
else {
include 'system/home.php';
}
?>

I sure I'm making this more complicated.

Thanks Jpadie


 
so are you looking for something that rewrites all your links into the form

<a href="products.php?link=somelink.php">text</a>

and then use some code like that above to include the right php file?

if so, then the easiest way of fixing this after you have written your site is to use mod_rewrite().

the steps would be
1. move all existing division/ directories to /division/rewrite/*
2. write a mod_rewrite() rule to redirect the user to products.php and append the requested uri to the query string as the link variable. you write the rule in an .htaccess file ideally
3. use code similar to the above (although there are easy ways to fine-tune it to a couple of lines) to parse the query string and select the right file.

this is much easier than trying to rewrite each and every link in php, but the latter is possible if you really need it. you do so using preg_replace_callback() (most easily).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top