Maybe it's just me, but can you elaborate mroe on what you are trying to do?
Are you trying to:
1.
Get the base/root directory name of the script you called?
Example: http://www.domain.com/stuff/wherever/something.php, get 'stuff' (per your first post).
2.
Get the directory name where the header is located at?
Example: http://www.site.com/scripts/header.php, get 'stuff'
3.
Get the full directory name of the script you called?
Example: http://www.domain.com/stuff/wherever/something.php, get 'stuff/wherever'.
If it's the first or third, use
$_SERVER['PHP_SELF']
If it's the second, use
__FILE__
In actuality, the variable $_SERVER['PHP_SELF'] will return to you the full directory name and file you called.
It will omit everything from http:// to the first /
i.e.: It will NOT include http://www.domain.com.
Instead, it will start from /stuff/blahblah....
Now, let's see if I'm successful in posting PHP code here...
PHP:
<?php
# Assume this is the full URL you want to work on.
# If you're using $_SERVER['PHP_SELF'], simply replace $parsedURL['path'] with the content of $_SERVER['PHP_SELF']
$URL = 'http://www.domain.com/stuff/wherever/something.php';
$parsedURL = parse_url ($URL);
# If using explode (), note that empty strings may occur due to the beginning '/'
# As such, the first directory you want is in index 1
$splitPath = explode ('/', $parsedURL['path']);
print_r ($splitPath);
/* Result:
Array
(
[0] =>
[1] => stuff
[2] => wherever
[3] => something.php
)
*/
# If using preg_split (), you can specify to omit empty strings
# However, this is supposedly a little slower than simple explode ()
$splitPath = preg_split ('/\//', $parsedURL['path'], 0, PREG_SPLIT_NO_EMPTY);
print_r ($splitPath);
/* Result:
Array
(
[0] => stuff
[1] => wherever
[2] => something.php
)
*/
?>