为了账号安全,请及时绑定邮箱和手机立即绑定

如何制作 URL 特定部分的面包屑

如何制作 URL 特定部分的面包屑

PHP
尚方宝剑之说 2021-06-17 18:01:51
我必须为网站的每个页面生成面包屑,因为 url 有点复杂。这是我的网址http://1.1.1.1/Company/?route=enterprise/projects/manage&id=52rw9649ffwerwd3d9018154§ion=newpanel现在我必须从“route=”之后的 url 获取“enterprise/projects/manage”,并生成每条路由的面包屑。下面是我正在使用的 PHP 代码,它只创建像“主页>>公司”这样的面包屑,而我需要像“企业>>项目>>管理”这样的面包屑。 // This function will take $_SERVER['REQUEST_URI'] and build a breadcrumb based on the user's current path    function breadcrumbs($separator = ' &raquo; ', $home = 'Home') {        // This gets the REQUEST_URI (/path/to/file.php), splits the string (using '/') into an array, and then filters out any empty values        $path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));        // This will build our "base URL" ... Also accounts for HTTPS :)        $base = ($_SERVER['HTTPS'] ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';        // Initialize a temporary array with our breadcrumbs. (starting with our home page, which I'm assuming will be the base URL)        $breadcrumbs = Array("<a href=\"$base\">$home</a>");        // Find out the index for the last value in our path array        $last = end(array_keys($path));        // Build the rest of the breadcrumbs        foreach ($path AS $x => $crumb) {            // Our "title" is the text that will be displayed (strip out .php and turn '_' into a space)            $title = ucwords(str_replace(Array('.php', '_'), Array('', ' '), $crumb));            // If we are not on the last index, then display an <a> tag            if ($x != $last)                $breadcrumbs[] = "<a href=\"$base$crumb\">$title</a>";            // Otherwise, just display the title (minus)            else                $breadcrumbs[] = $title;        }        // Build our temporary array (pieces of bread) into one big string :)        return implode($separator, $breadcrumbs);        //return parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);    }     ?> `
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 152 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信