brooksh Posted November 6, 2011 Share Posted November 6, 2011 This script works fine except, the a href only displays baseurl/current_folder instead of baseurl/other_folder/other_folder/current_folder I'm sure it's simple, but I can't figure it out. function breadcrumbs($separator = '', $home = 'Home') { $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; $breadcrumbs = array("<p><a href=\"$base_url\">$home</a></p>"); $last = end(array_keys($path)); foreach ($path AS $x => $crumb) { $title = ucwords(str_replace(array('.php', '_'), Array('', ' '), $crumb)); $title = ucwords(str_replace(array('.html', '_'), Array('', ' '), $crumb)); if ($x != $last){ $breadcrumbs[] = "<p><a href=\"$base_url$crumb\">$title</a></p>"; }else{ $breadcrumbs[] = "<p>$title</p>"; } } return implode($separator, $breadcrumbs); } echo breadcrumbs(); Quote Link to comment Share on other sites More sharing options...
xyph Posted November 6, 2011 Share Posted November 6, 2011 print_r on your $path to verify it contains what you expect. Quote Link to comment Share on other sites More sharing options...
brooksh Posted November 6, 2011 Author Share Posted November 6, 2011 There aren't any errors in the script that I see, just I don't know how to get the href to display. For Example: Home > Page1 > Subdirectory1 > Link Right now the href is www.mydomain.com/link when it should be www.mydomain.com/page1/subdirectory1/link Quote Link to comment Share on other sites More sharing options...
brooksh Posted November 6, 2011 Author Share Posted November 6, 2011 Oh Well, just changed the script function breadcrumbs(){ $bread = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))); $base_url = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/'; $url = '/'; $returnString = "<span class='bc0'><p><a href='$url'>home</a></p>"; for($i=1;$i<count($bread)-1;$i++){ $url.=$bread[$i].'/'; $returnString .= "</span> <span class='bc$i'><p><a href='$url'>$bread[$i]</a></p>"; } echo $returnString.'</span>'; } breadcrumbs(); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.