<?php
$protocol = 'http://';
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "on")
{
$protocol = 'https://';
}
$host = strip_tags($_SERVER['HTTP_HOST']);
// Get the URL, strip any tags for security, remove the protocol and then explode each part into an array.
$url = strip_tags($_SERVER['REQUEST_URI']);
$url = str_replace($protocol, '', $url);
//Remove a trailing slash if there is one
$url = preg_replace('/\/$/', '', $url);
$url = explode('/', $url);
// Get number of crumbs we'll have.
$crumb_count = count($url);
// Initialize crumb URLs
$crumb_url = $protocol.$host.$url[0].'/';
// Initialize breadcrumbs with Home link
$breadcrumbs = '<a href="'.$crumb_url.'">Home</a>';
// Initialize last bool.
$last = FALSE;
// Process each crumb, skipping the first which is Home.
for ($i=1; $i < $crumb_count; ++$i)
{
if ($i == ($crumb_count-1))
{
// End of the line!
$last = TRUE;
}
// Build this crumb's URL.
$crumb_url .= $url[$i];
// Add trailing slash if not last crumb
$crumb_url .= (!$last) ? '/' : '';
// Replace all dashes and underscores with spaces for URL title.
$title = str_replace(array('-','_'), array(' ',' '), $url[$i]);
// uppercase each word and convert all symbols to HTML entities for security.
$title = htmlentities(ucwords($title), ENT_QUOTES);
$breadcrumbs .= ' > ';
// If not last item, which should be current page, make a link to that crumb, else just show title.
$breadcrumbs .= (!$last) ? '<a href="'.$crumb_url.'" title="'.$title.'">'.$title.'</a>' : $title;
}
echo $breadcrumbs;
?>