Page 1 of 1

Parsing a folder name from a URL

Posted: Wed Nov 05, 2003 8:21 am
by Toneboy
I think this comes under the "don't laugh" section for regulars and professionals. :)

Basically I'm in the process of designing a site which isn't particularly deep (folder-wise), and so I thought it would be nice to have one of those Home > Folder > This Page lines on each page, much like you can see above here. The "Home" link remains static, and the "This Page" display is defined from page to page. However what I would like to do is generate the "Folder" link dynamically instead of having to define that on each page as well.

Code: Select all

$thispage = $PHP_SELF;
// gives you /directory/page.php
$thisdir = substr($thispage, 1);
// gives you directory/page.php

// then I need something to elimate the /page.php section
I was then planning to match up the result with corresponding entries in a MySql database to show on the display.

I did take a look in the manual, but upon further looking at preg_match I realised I was looking at completely the wrong thing. I've looked at preg_match, and preg_replace, neither seems to be the right thing to use. Would preg_split be a better way to go, or is there something which makes the whole thing easier?

Posted: Wed Nov 05, 2003 8:42 am
by JAM
Ahhh... bread crumbs...

Lookup pathinfo() and explode() in the manual. To further elaborate, pathinfo woulöd give you a path to work with, and explode is used to break down a string into pieces for later usage.

Beginner or not, I think it will make sence to you after you take a look at it.

Posted: Wed Nov 05, 2003 8:59 am
by Toneboy
All a matter of knowing where to look!

Thanks very much for pointing me in the right direction, Jam - very much appreciated.