roundcorners Posted June 6, 2009 Share Posted June 6, 2009 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 More sharing options...
jeffman Posted June 6, 2009 Share Posted June 6, 2009 http://www.php.net/manual/en/function.getcwd.php Link to comment Share on other sites More sharing options...
roundcorners Posted June 7, 2009 Author Share Posted June 7, 2009 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 More sharing options...
roundcorners Posted June 7, 2009 Author Share Posted June 7, 2009 thank you for your help, I worked it out, string = basename(dirname(__FILE__)) this returns the folder name. Link to comment Share on other sites More sharing options...
boen_robot Posted June 7, 2009 Share Posted June 7, 2009 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.