Parsing a folder name from a URL

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
User avatar
Toneboy
Forum Contributor
Posts: 102
Joined: Wed Jul 31, 2002 5:59 am
Location: Law, Scotland.
Contact:

Parsing a folder name from a URL

Post 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?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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.
User avatar
Toneboy
Forum Contributor
Posts: 102
Joined: Wed Jul 31, 2002 5:59 am
Location: Law, Scotland.
Contact:

Post by Toneboy »

All a matter of knowing where to look!

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