<?php
$locArray = array(
"" => "Home Page",
"img" => "Image Gallery",
"dl" => "Downloads",
"naruto" => "Naruto Shippuden",
"bbs" => "Community",
"contact" => "Contact",
"about" => "About Us"
);
function location(){ //put this in global file
global $siteURL, $locArray, $title; //I have title as a global, you can passed it as an argument
$temp = explode("/", $_SERVER['REQUEST_URI']);
$i = 0;
$theURL = $siteURL;
$retval = "<a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
for($i = 1; $i < sizeof($temp)-1; ++$i){
$theURL .= "/" . $temp[$i];
$retval .= " -> <a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
}
$retval .= " -> $title"; //title = the title of the current page
return $retval;
}
?>
- <?php
- $locArray = array(
- "" => "Home Page",
- "img" => "Image Gallery",
- "dl" => "Downloads",
- "naruto" => "Naruto Shippuden",
- "bbs" => "Community",
- "contact" => "Contact",
- "about" => "About Us"
- );
- function location(){ //put this in global file
- global $siteURL, $locArray, $title; //I have title as a global, you can passed it as an argument
- $temp = explode("/", $_SERVER['REQUEST_URI']);
- $i = 0;
- $theURL = $siteURL;
- $retval = "<a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
- for($i = 1; $i < sizeof($temp)-1; ++$i){
- $theURL .= "/" . $temp[$i];
- $retval .= " -> <a href=\"".$theURL."\" title=\"".$locArray[$temp[$i]]."\" target=\"_self\"> ".$locArray[$temp[$i]]."</a>";
- }
- $retval .= " -> $title"; //title = the title of the current page
- return $retval;
- }
- ?>
What this does is the following:
Lets say I have a website at
http://www.domain.com, so I set the $siteURL to that URL.
Now, if I call this function from
http://www.domain.com/img/naruto/,
and the page has a title called: "Naruto: Shippuden High Quality Wallpapers".
This function will return the following result:
<a href="http://www.domain.com/" title="Home Page" target="_self">Home Page</a>->
<a href="http://www.domain.com/img/" title="Image Gallery" target="_self">Image Gallery</a>->
<a href="http://www.domain.com/img/naruto/" title="Naruto Shippuden" target="_self">Naruto Shippuden</a>->
Naruto: Shippuden High Quality Wallpapers
- <a href="http://www.domain.com/" title="Home Page" target="_self">Home Page</a>->
- <a href="http://www.domain.com/img/" title="Image Gallery" target="_self">Image Gallery</a>->
- <a href="http://www.domain.com/img/naruto/" title="Naruto Shippuden" target="_self">Naruto Shippuden</a>->
- Naruto: Shippuden High Quality Wallpapers
NOTE: I put each anchor in a new line so you can have a clear look; the code produced, doesn't do the linebreak.
I would like some experts to have a clear look at my code and comment on it, is it good? is it bad? should I improve it? and etc.
PS: feel free to use the code if you like it ^^.