Page 1 of 1

Using PHP to identify the folder the page is in?

Posted: Sat Mar 25, 2006 5:49 pm
by sampage
Sorry this is a long post, in short: Is it possible to get PHP to identify the folder a page sits in?

I have a header.php page which has tabs on it as a menu system, this page is loaded into all other PHP pages when they load. When a person goes to the different areas (i.e. Information, Search) the tab for the area needs to update so that it is highligted.

Rather than having the coding on every page and setting the tabs to update manually, does anyone know of a way to get the master page, which the header is loaded into, to be able to detect which folder it sits in (i.e. /information/ or /search/ ) which I can then use to update the header page with, reflecting which tab should be selected.

The trouble with putting the header page into each page seperatly, rather than loading from an external document, is that when i make changes I have to update every page on the site!!!

Any advice would be really appreciated, sorry for the long post!

Posted: Sat Mar 25, 2006 5:58 pm
by hawleyjr

Code: Select all

dirname($_SERVER['PHP_SELF']);

Posted: Sat Mar 25, 2006 6:08 pm
by sampage
Thank you for your reply, perfect!

Say I have this code:

Code: Select all

$folder = dirname($_SERVER['PHP_SELF']);
Which actually equalled /en/people/information/group/ - what would be a method of searching the directory tree for "people"?

I have used PHP searches before, but not for some time - sorry to go back to basics!

Posted: Sat Mar 25, 2006 6:25 pm
by hawleyjr
I'm not sure what you mean by 'search'

Are you just trying to see if the current page is a child of the 'people' directory?

Posted: Sun Mar 26, 2006 1:48 am
by sampage
Yes thats right, would it inolve a LIKE search, although I only know how to do this when looking through a database for records.

I need something along the lines off:

When $folder contains 'people' $mainfolder="1"

//

When $folder contains 'information' $mainfolder="2"

And so forth, thanks for your time on this one!

Posted: Sun Mar 26, 2006 1:50 am
by feyd
strpos() or an explode() followed by an array_search():idea: