Jump to content

Get Current Folder


roundcorners

Recommended Posts

Hi all, please can help me understand how to retrieve the current folder name?I want to populate my window title with the value of the folder name containing the index page being viewed.I also want to use this value to add an id of active to the appropriate nav menu item. Is there a super global variable or built-in function with which I can get the folder name?Please help.thanks in advance

Link to comment
Share on other sites

thank you, is there a function I can use to get only the current folder name?Or do I have to use getcwd() and explode() or something else that will manipulate the string?

Link to comment
Share on other sites

thank you, is there a function I can use to get only the current folder name?Or do I have to use getcwd() and explode() or something else that will manipulate the string?
Yeah. That might be the best solution.
$path = explode(getcwd(), DIRECTORY_SEPARATOR);$cwdName = $path[count($path) - 1];

Or, you could subtract the dirname() from the full path, like:

$path = getcwd();$cwdName = substr($path, strlen(dirname($path)));

I think the former might be slightly faster though - at least it should be in theory. The first does more things at the C layer, whereas the second does more things in the PHP layer, which should be inherently slower.[edit]Huh... yeah... your latter solution might be even better that both of those.[/edit]

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...