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(); Link to comment https://forums.phpfreaks.com/topic/250570-breadcrumb-problems/ 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. Link to comment https://forums.phpfreaks.com/topic/250570-breadcrumb-problems/#findComment-1285623 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 Link to comment https://forums.phpfreaks.com/topic/250570-breadcrumb-problems/#findComment-1285707 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(); Link to comment https://forums.phpfreaks.com/topic/250570-breadcrumb-problems/#findComment-1285716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.