testpath.phps

<?php
 
function show_path() { // This function will show the path  by directory
global $SERVER_NAME;
global $PATH_TRANSLATED;
global $SCRIPT_NAME;
 
    /* Return the Script name as an array for the path menu i.e.  home :subjects : etc.
    Get rid of everything apart from the file name
 
    strrchr ($SCRIPT_NAME, "/") returns portion of string that starts at the last occurrence of / and goes to the end of string
    Substr returns the portion of string that begins after the length parameter (length of the string starts at 0, which would be /). 
    */
 
    $dir = substr(strrchr ($SCRIPT_NAME, "/"), 1);
    //echo 'The file name - '.$dir; //can be unescaped to make sure script is working correctly
 
    // Remove the file name from the scriptname by replacing the filename with
    $path = str_replace("$dir", "", $SCRIPT_NAME);
    //echo '<p>Removed filename from path - '.$path; //can be unescaped to make sure script is working correctly
 
    // Remove the first and last /
    $path = substr("$path", 1, -1);
    //echo '<p>Removed the first and last / from path - '.$path; //can be unescaped to make sure script is working correctly
 
    // Print out the navigation links
    // The first href should be the full path for the site but the other links will be to only the site directories
 
echo "<p><p><a class=link href=\"/\">Home</a> > ";
if($path != ""){
 
    // Return the path as an array by spliting at /
    $path = split( "/", $path);
 
    if(sizeof($path) != 0)    {
    $start = 0;
    $stop = count($path); //number of elements in array
    //$i < $stop has to be less than total number of elements in array because array starts at zero
        for ($i = $start; $i < $stop; $i++) {  //for all elements in the array until the end
         //start printing the link
            print "<a class=link href=\"/";   
            for ($j = $start; $j <= $i; $j++) { //for each specific element print the value of the element
                print "$path[$j]/";
            }
            //for each specific element print the value of the element with the first character in uppercase
            print "\">".ucfirst($path[$i])."</a> > \n";  
        }
    }
 
print "<a class=link href=\"$dir\">$dir</a>"; //print link to current file
}
 
}
 
show_path();
 
?>