Welcome to WebmasterWorld Guest from 54.157.225.99

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

$ SERVER function for file name

     
7:24 am on May 24, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1542
votes: 0


If you have mydomain.com/category/page.php

$_SERVER['SCRIPT_FILENAME'] gives you category/page.php

But is there something that gives you just page.php

If not how do you edit category/page.php or whatever it may be, e.g. category1/category2/page.php so it becomes only page.php?
8:22 am on May 24, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 21, 2002
posts: 1542
votes: 0


sorry worked it out:
$path = $_SERVER['SCRIPT_NAME'];
$newpath = basename($path);
$arr = explode(".", $newpath);

Is that the best way?
11:05 pm on June 1, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12541
votes: 1


basename is what I would have suggested. There are optional parameters you can pass to the function as well, possibly saving you additional programming steps.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members