PHP 动态面包屑导航
我从某人那里得到了这段代码,它运行得很好,我只想删除数组最后一个元素中的链接:
//get rid of empty parts
$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>";
}
print implode(' > ', $result);
这将输出例如: 内容>>常见>文件
我只想删除最后一项的链接 - “文件”只是纯文本.. 我尝试自己计算数组项,然后如果数组项是最后一项,则以纯文本形式打印最后一项..但我仍然是菜鸟,我还没有设法获得正确的结果..
谢谢!
I got this code from someone and it works very well, I just want to remove the link from the last element of the array:
//get rid of empty parts
$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>";
}
print implode(' > ', $result);
This will output for example:
Content > Common > File
I just want a to remove the link from the last item - "File" to be just plain text..
I tried myself to count the array items and then if the array item is the last one then to print as plain text the last item.. but I'm still noob, I haven't managed to get a proper result..
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该有效:
This should work:
您可以简单地调整现有代码以使用“正常”循环(而不是 foreach 迭代器)来实现此目的。
例如:
注意:我目前无法访问 PHP,因此上面的内容可能并非没有错误,但您应该明白了。
You could simply tweak your existing code to use a 'normal' loop (rather than a foreach iterator) to achieve this.
For example:
N.B: I don't have access to PHP at the moment, so the above might not be error free, but you should get the idea.