I used the code found here for dynamic php breadcrumbs for my website. It works great! however, If I nest a folder more than 1 deep, It causes errors.
Here's the code that I have currently for the breadcrumbs.
<?php
function breadcrumbs($separator = ' » ', $home = 'Home') {
$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
$base = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
$breadcrumbs = Array("<a href=\"$base\">$home</a>");
$last = end(array_keys($path));
foreach ($path AS $x => $crumb) {
$title = ucwords(str_replace(Array('.php', '_'), Array('', ' '), $crumb));
if ($x != $last)
$breadcrumbs[] = "<a href=\"$base$crumb\">$title</a>";
else
$breadcrumbs[] = $title;
}
return implode($separator, $breadcrumbs);
}
?>
You are here: <?= breadcrumbs(' ♥ ') ?>
The easiest place to see a live example is here. If you click on the third link on the breadcrumbs, it ignores the second nested folder. I don't know enough PHP to trouble shoot the problem and how to fix it. I would think ideally it would watch for nested folders in the url.