简单动态面包屑 [英] Simple dynamic breadcrumb

查看:413
本文介绍了简单动态面包屑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为此脚本对周围的任何菜鸟都非常感兴趣:)包括我:)

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']"和

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) . ' ');
}

这篇关于简单动态面包屑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆