php:简单的面包屑解决方案?
嘿伙计们, 我正在研究一个非常简单的面包屑路径解决方案,但是我有一件小事让我烦恼。
PATH 是例如文件夹/子文件夹/子子文件夹 我只是分割路径并创建指向它的链接。真的很简单。
// breadcrumb path
$crumb = explode("/", PATH);
if (PATH != 'root' && realpath(PATH)) {
print "<div class='breadcrumbs'>";
$newpath = '';
foreach($crumb as $value) {
$newpath .= $value;
print "<a href='" . QUERY . $newpath ."'>$value</a> > ";
$newpath .= '/';
}
print "</div>";
}
然而,唯一让我烦恼的是面包屑路径看起来像这样:
文件夹>子文件夹>子子文件夹>
你能看到>吗?在最后。即使那里没有另一个子子子文件夹,我得到这个>箭。当然,目前是这样设置的,但是我想不出一个简单的解决方案来摆脱最后一个箭头。
感谢您的帮助
hey guys,
i'm working on a very simple breadcrumb-path solution, however i have one little thing that kind of bugs me.
PATH is e.g. folder/subfolder/subsubfolder
i'm simply splitting the PATH and i'm creating links to it. really simpel.
// breadcrumb path
$crumb = explode("/", PATH);
if (PATH != 'root' && realpath(PATH)) {
print "<div class='breadcrumbs'>";
$newpath = '';
foreach($crumb as $value) {
$newpath .= $value;
print "<a href='" . QUERY . $newpath ."'>$value</a> > ";
$newpath .= '/';
}
print "</div>";
}
however the only thing that bugs me is that the breadcrumb path looks like this:
folder > subfolder > subsubfolder >
can you see the > at the end. even though there is not another subsubsubfolder there i'm getting this > arrow. of course it's currently set that way, however i cannot think of an easy solution to get rid of the last arrow.
thank you for your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给你:
同时尝试为变量使用更具暗示性的名称。
Here you go:
Also try to use more suggestive names for your variables.
将您的代码更改为(未经测试!):
Change your code to (not tested!):