Welcome to WebmasterWorld Guest from 54.226.25.231

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

$ SERVER function for file name

     

whatson

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

WebmasterWorld Senior Member 10+ Year Member



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?

whatson

8:22 am on May 24, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



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

Is that the best way?

coopster

11:05 pm on Jun 1, 2012 (gmt 0)

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month