I have copied the following code from: Bootstrap Breadcrumbs with PHP and it works perfectly but It turns out that the web where I will implement it has a structure that is the following: link and the web is working showing the breadcrumbs in the following way:
Inicio » U » Usuario » Cualquier Pag
And I would like what you show to do so:
Inicio » Cualquier Pag
Since in my project the web:
https://virtual.jesuministrosymas.com.ve/u/usuario/
https://virtual.jesuministrosymas.com.ve/u/
https://virtual.jesuministrosymas.com.ve/
They will have a behavior according to the user's login and once the session has started all the previous webs go directly to
https://virtual.jesuministrosymas.com.ve/u/usuario/index.php
The code I am implementing is the following:
<?php
function breadcrumbs($sep = ' » ', $home = 'Inicio') {
$bc = '<ul class="breadcrumb">';
//Get the server http address
$site = 'https://'.$_SERVER['HTTP_HOST'];
//Get all vars en skip the empty ones
$crumbs = array_filter( explode("/",$_SERVER["REQUEST_URI"]) );
//Create the homepage breadcrumb
$bc .= '<li><a href="'.$site.'">'.$home.'</a>'.$sep.'</li>';
//Count all not empty breadcrumbs
$nm = count($crumbs);
$i = 1;
//Loop through the crumbs
foreach($crumbs as $crumb){
//grab the last crumb
$last_piece = end($crumbs);
//Make the link look nice
$link = ucfirst( str_replace( array(".php","-","_"), array(""," "," ") ,$crumb) );
//Loose the last seperator
$sep = $i==$nm?'':$sep;
//Add crumbs to the root
$site .= '/'.$crumb;
//Check if last crumb
if ($last_piece!==$crumb){
//Make the next crumb
$bc .= '<li><a href="'.$site.'">'.$link.'</a>'.$sep.'</li>';
} else {
//Last crumb, do not make it a link
$bc .= '<li class="active">'.ucfirst( str_replace( array(".php","-","_"), array(""," "," ") ,$last_piece)).'</li>';
}
$i++;
}
$bc .= '</ul>';
//Return the result
return $bc;
}
echo breadcrumbs();
?>