Forum Moderators: coopster
<?php
// here we have the location of where we are now
// this holds a list of all the folders, files and
// request strings in this one variable
// we will use this to get every single location possible
// in the current directory
$location = $_SERVER['REQUEST_URI'];// to start of we are going separate the strings
// from the paths, to do this we use the function explode
// to break the path into two values (paths/files and string variables)
$remove_string = explode('?', $location);// once we have these two vars we need to assign them to there own variables
// additional vars =?request=this&that=whatever
$additional_vars = $remove_string[1];// and the paths /root/to/where/you/are/now
$directory_path = $remove_string[0];// now we have the folder listing we use the function
// explode again to separate each directory into
// there own
$bits = explode('/', $directory_path);// create a new array for all the directories, files and
// strings to be stored
$pages = array();// we now assign each directory to a value in to an array
foreach ($bits as $key=>$value)
{
// check to see if the key has a value
if(!empty($key))
{
// assign it to an array we have called above $pages
// i have assigned them to a second level as
// this will keep this in a good order
// and will make it easier to access later on
$pages['directories'][$key] = ($value);
}
}// we can assign the up most level to the array
// this makes it easier as it is an associated name
$pages['top'] = $bits[1];// same as above but for the upper most file
// so if we are in music/bands/rockmusic.php
// this value will be rockmusic.php
$pages['current'] = end($bits);// to get a level below we count the length of the array
// subtract two from the array as array's start from zero
$pages['down_one_level'] = $bits[count($bits)-2];// check to see if there are any additional variables
//?something=this
if(!empty($additional_vars))
{
// if they exist
// explode them again using the & as the deliminator
$var_bits = explode('&',$additional_vars);
// loop through each variable
foreach($var_bits as $new_var_bit => $new_value)
{
// explode them at the = to get the value and the new key
$new_var_values = explode('=',$new_value);
// set the value of the key
$variable = $new_var_values[0];
// set the value of the variable
$variable_value = $new_var_values[1];
// assign each to the array
$pages['request'][$variable] = $variable_value;
}
}// sort the array
rsort($pages);// show the results by printing out all the variables in the array
echo "<pre>";
print_r($pages);
echo "</pre>";
?>
From this simple "tutorial" you will be able to call the "one" from the URL useing the $pages array.
For example, you can call the most current page you are one and for you personal query you can use the $additional_vars to grab the variables you need and then use them how you need to in php.
Good luck - hope i have helped
Del