I would like to put on my page the directory structure of where the user is: so, if the URL was mydomain.com/ subfolder1/ subfolder2 / page-name.html they could see that so on the page you would have something like: "you are here:" subfolder1 --- subfolder2 --- pagename (without the url) with all of these being links. OK, the first thing to do is to grab the URL and I can do that as: $url = $_SERVER['REQUEST_URI']; but how do I split out the URL into the relevant parts OH !!! sometimes the subfolder2 is not present, only subfolder 1 so the code would need to allow for whatever is present THANKS !
Let's try explode function in your case $dir_array = explode("/", $url); PHP: You will have to use the count function to know how may element your $dir_array haves
$domain = "http://www.yourdomain.com/"; $url = $PHP_SELF; $url = explode('/',$url); $links = array(); foreach($url AS $key->$value) { $folder = "".$folder."/$value"; $links[$value] = "/ <a href=\"$domain/$folder/\">$value</a> "; }; foreach($links AS $key->$value) { echo " $value"; }; Code (markup): Not actually tested it but presume it works. WIll test later properly.
OK, I'll help you from A, now is Z, just copy and paste: <? //Parse URL version 1 //(C) 2004 haibuihoang@yahoo.com //For example, $url will be $url= "http://www.yourdomain.com/sub1/sub2/yourpage.htm"; $parsed_url=parse_url($url); $sub_folder = explode('/',$parsed_url['path']); $domain=$parsed_url['scheme'].'://'.$parsed_url['host']; $folder=""; $max=count($sub_folder); echo 'You are here: '; for ($i=0;$i<$max;$i++) { $folder.= ($max-1==$i)? $sub_folder[$i] : $sub_folder[$i].'/'; $folder_url= $domain.$folder; if (0==$i) { echo "<br><a href=\"$folder_url\">".$domain.' </a>'; } else { echo "/<a href=\"$folder_url\">".$sub_folder[$i].' </a>'; } } ?> PHP:
thanks - that didnt quite work - for others, here is the correct script: $url = $_SERVER['REQUEST_URI']; $parsed_url=parse_url($url); $sub_folder = explode('/',$parsed_url['path']); $domain=$parsed_url['scheme'].$parsed_url['host']; $folder=""; $max=count($sub_folder); echo 'You are here: '; for ($i=0;$i<$max;$i++) { $folder.= ($max-1==$i)? $sub_folder[$i] : $sub_folder[$i].'/'; $folder_url= $domain.$folder; if (0==$i) { echo '<br><a href="http://www.domain.co.uk'.$folder_url.'">'.$domain.' </a>'; } else { echo '/<a href="http://www.domain.co.uk'.$folder_url.'">'.$sub_folder[$i].' </a>'; } }
So, this displays the "breadcrumb trail" by folder name - anyone got any pointers on how one might go about susbstituting folder names for "real" names i.e. if there's an exisitng folder with an abbreviated name and I wanted to not display this, and use a full name instead? For example... if I had a folder /h2gaads/ and I really want to show "How to get ahead in Advertising" on the screen? Can this be done and what level of difficulty would be involved?
I guess you must have something like database to store the folder name? Or you store it somewhere? If you use a Database, I think there'd be no problem. The later cases, for example, you may store a file name "folder.info" or "info.php" in each directories. Once you get URL to the directory you want (like my previous example), read it, then display it.
Ah, top tip, goldensea80, thankyou. My database experince is limited so I will investigate the folder.info route until I'm better with dbs. Cheers
I've been looking for something similar. It seems that all the breadcrumb stuff I've found will not work with this current system. I'm sure there's a way around this, but I'm just not that well versed in PHP. See I pretty much design a "template" then call certain information such as content, title, and navigation. Placed before <html> on index.php in root (this is my template file). <? $fullPath = '/home/traeonna.com/public_html/ayablue'; $dir = $_GET['dir']; $page = $_GET['page']; if(!isset($dir)) { $dir = 'home'; $page = 'index'; } ?> Code (markup): Here are my includes for content, title, and navigation. <? include($fullPath . '/' . $dir . '/' . $page . '.php'); ?> <? include($fullPath . '/' . $dir . '/' . $page . '_title.php'); ?> <? include($fullPath . '/' . $dir . '/' . $dir . '_nav.php'); ?> Code (markup): An example of how the URL looks... http://ayablue.traeonna.com/index.php?dir=portfolio_amanda&page=fb_sa I would like a breadcrumb as such... Home > Amanda's Portfolio > Fruits Basket - Ayame Sohma I can print and that will print the directory names and file names, but there's no links, and I kinda would like that. Home > <?php print $dir . ' > ' . $page; ?> Code (markup): I'm so frustrated.
Hey, I'm new to PHP but I think some of this code would work with what I'm trying to do. I was wondering if you would know how to display a particular image depending on what section of the website you are in. example: (something.com/the-band) or (something.com/the-band/something) the photo would be "the-band.jpg" but if you were in (something.com/music) or (something.com/music/something) the photo would be "music.jpg" If you or anyone could shed some light, it would be much appreciated. Cheers, Ross
You guys made this much more complicated than it should be For a URL like this:mydomain.com/ subfolder1/ subfolder2 / page-name.html $uri = $_SERVER['REQUEST_URI']; list($trash, $subfolder1, $subfolder2, $pagename) = split("/", $uri); PHP: Then you can do whatever with each variable
You can also use explode( ) function to break it into array pieces $url = $_SERVER['REQUEST_URI']; $array = explode("/",$url); echo $array[?]; ///which folder would you want to access ? PHP: