Posts: 1,832
Location: Somewhere else entirely
|
It is certainly possible, and can be done in a number of ways. Probably simplest is to use the explode function:
PHP Code:
$url = $_SERVER['PHP_SELF'];
$parts = explode("/",$url);
$two_folders_only = "/".$parts[1]."/".$parts[2];
To explain the above:
explode converts a string into an array, dividing it into bits around the character you specify, in this case '/' . So in the above example, if $url were to be '/Citadel/FAQ/Part1/display.php', $parts would be an array with element 0 ='', 1='Citadel', 2='FAQ', 3='Part1', 4='display.php'. (Arrays start from 0, and the first element is the empty string, since $url starts with /, the character we are using as the divider)
The bits of it you want are always in element 1 and 2, so you can pick those out, add in a couple of slashes and you have the first two folders but no more, no matter how many there might be. The full stop is used to join strings in PHP.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';
Please login or register to view this content. Registration is FREE (aka MSN handwriting for forums)
|