我从某人那里获得了这个代码,创建一个动态的面包屑几乎是完美的,但是只有一点小故障,因为它在面包屑之前回应了两个分隔符:
$crumbs = explode("/",$_SERVER["REQUEST_URI"]);
foreach($crumbs as $crumb){
echo ucfirst(str_replace(array(".php","_"),array(""," "),'>' . $crumb));
}
它回应:
“>>内容>常见>文件”
我希望它看起来像
“内容>共同→1”
如果有人能告诉我如何为阵列中除最后一个(文件)之外的所有项目添加链接,我将深深感激?
非常感谢大家,这个网站通过实例帮助我学习了很多PHP!
答案 0 :(得分:2)
也许这样的事情可以做到:
<击> //摆脱空白部分 $ crumbs = array_filter($ crumbs);
$result = array();
$path = '';
foreach($crumbs as $crumb){
$path .= '/' . $crumb;
$name = ucfirst(str_replace(array(".php","_"),array(""," "), $crumb));
$result[] = "<a href=\"$path\">$name</a>";
}
echo implode(' > ', $result);
击> <击> 撞击> 的更新强>
$result = array();
$path = '';
$num = count($crumbs);
for ($j=0; $j<$num; $j++) {
$crumb = $crumbs[$j];
if ($crumb == '') {
continue;
}
$path .= '/' . $crumb;
$name = ucfirst(str_replace(array(".php","_"),array(""," "), $crumb));
if ($j < ($num - 1)) {
$result[] = "<a href=\"$path\">$name</a>";
} else {
$result[] = $name;
}
}
echo implode(' > ', $result);