homepage Welcome to WebmasterWorld Guest from 54.83.133.189
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Pubcon Website
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Get php file name WITHOUT path
Jakotsu




msg:3317424
 4:06 am on Apr 21, 2007 (gmt 0)

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:

$_SERVER['SCRIPT_FILENAME']
$_SERVER['SCRIPT_NAME']
$_SERVER['REQUEST_URI']

But *ALL* of those methods return "projects/main.php"... d'oh! How can I retrieve the file name ONLY, without path?

Thanks in advance

 

eelixduppy




msg:3317427
 4:19 am on Apr 21, 2007 (gmt 0)

You can use basename [php.net] on any one of those strings to return just the name of the script.

mayurapilly




msg:3317937
 11:16 pm on Apr 21, 2007 (gmt 0)

or you could do something like

$arrStr = explode("/", $_SERVER['SCRIPT_NAME'] );
$arrStr = array_reverse($arrStr );

echo("Script is " . $arrStr[0]);

it is a little more clumsy than basename, but it is one solution and an idea on how to pull data from an array.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved