我已附上面包屑,现在正在运行。但如何整理结果才能发挥作用。
此代码
<?php
$crumbs = explode("/",$_SERVER["REQUEST_URI"]);
foreach($crumbs as $crumb){
ucfirst(str_replace(array(".php","_"),array(""," "),$crumb) . ' ');
}
$urls = "http://example.com";
foreach($crumbs as $crumb){
$urls .= "/".$crumb;
echo '<li><a href="'.$urls.'">';
echo $crumb;
echo '</a></li>';
}
?>
,结果是
Home / / pages / contact
如何在家后删除一个斜杠?
和url的结果
http://example.com//pages/contact
我试图修复但仍未解决
答案 0 :(得分:0)
添加每个&#39;面包屑&#39;循环中的数组,然后在循环后内插数组,添加斜杠。
$urls = "http://example.com";
$breadcrumbs = array();
foreach($crumbs as $crumb){
$breadcrumbs[] = "<li><a href='$urls/$crumb'>$crumb</a></li>";
}
echo '/'.implode('/',$breadcrumbs);