[wp-hackers] PHP one liner

Stephen Cropp steve at de-generationx.net
Tue Dec 14 11:47:59 UTC 2004

Kitty wrote:
> Here's a quick bit of code to get the filename out of a URL/path:
> Given $_SERVER['PHP_SELF'] == '/some/dir/index.php'
> <?php $page = array_pop( explode( '/', $_SERVER['PHP_SELF'] ) ); ?>
> $page will contain the 'index.php', no regexs, no fuss.

This is a good way of doing it, however with the viral nature of 
mod_rewrite spreading everywhere, I personally do it using 
$_SERVER['REQUEST_URI'] instead.

I did it this way in my pathfinder() function that gets used for 
navigation on most chunks of my site. For the very fact that using 
PHP_SELF did not work if the path you wanted was really the mod_rewrite 
version. You can view the full code for my pathfinder() code at the 
following address:


(aka Korgan)

More information about the hackers mailing list