| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Pubcon Platinum Sponsor 2014|
|Get php file name WITHOUT path|
I have a page in Apache with a path like "localhost/projects/main.php" and I need to retrieve only "main.php", or whatever the current PHP page name is.
Anyone would think that some of these methods should return the file name:
But *ALL* of those methods return "projects/main.php"... d'oh! How can I retrieve the file name ONLY, without path?
Thanks in advance
You can use basename [php.net] on any one of those strings to return just the name of the script.
or you could do something like
$arrStr = explode("/", $_SERVER['SCRIPT_NAME'] );
$arrStr = array_reverse($arrStr );
echo("Script is " . $arrStr);
it is a little more clumsy than basename, but it is one solution and an idea on how to pull data from an array.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved