问题描述
我认为此脚本对周围的任何菜鸟都非常感兴趣:)包括我:)
I think this script is of big interest to any noob around here :) including me :)
我想要创建的是一个可以在任何文件中使用的小代码,它将生成像这样的面包屑:
What I want to create is a little code that I can use in any file and will generate a breadcrumb like this:
如果文件名为" website.com/templates/index.php ",则面包屑应显示:
If the file is called "website.com/templates/index.php" the breadcrumb should show:
Website.com > Templates
^^链接 nbsp; 文字
^^ link ^^plain text
如果文件名为" website.com/templates/template_some_name.php ",则面包屑应显示:
If the file is called "website.com/templates/template_some_name.php" the breadcrumb should show:
Website.com > Templates > Template Some Name
^^链接; ^^纯文本
^^ link ^^link ^^plain text
推荐答案
嗯,从您提供的示例中,它看起来像是"$ _SERVER ['REQUEST_URI']"和 explode()函数可以为您提供帮助.您可以使用explode将域名后面的URL分解为一个数组,并在每个正斜杠处将其分隔.
Hmm, from the examples you gave it seems like "$_SERVER['REQUEST_URI']" and the explode() function could help you. You could use explode to break up the URL following the domain name into an array, separating it at each forward-slash.
作为一个非常基本的示例,可以实现如下所示:
As a very basic example, something like this could be implemented:
$crumbs = explode("/",$_SERVER["REQUEST_URI"]);
foreach($crumbs as $crumb){
echo ucfirst(str_replace(array(".php","_"),array(""," "),$crumb) . ' ');
}
这篇关于简单动态面包屑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!