我有这个脚本几乎完全按照我的意愿去做但我需要删除连字符。
它使用我网站的页面生成面包屑,但我需要它来执行此操作
Home > Aaa bbb ccc > Aaa bbb
而不是
Home > Aaa-bbb-ccc > Aaa-bbb
我知道我需要使用PHP explode()函数,但我似乎无法弄清楚放在哪里。
<?php
function breadcrumbs($separator = ' > ', $home = 'Home') {
$path = array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)));
$base_url = substr($_SERVER['SERVER_PROTOCOL'], 0, strpos($_SERVER['SERVER_PROTOCOL'], '/')) . '://' . $_SERVER['HTTP_HOST'] . '/';
$breadcrumbs = array("<a href=\"$base_url\">$home</a>");
$tmp = array_keys($path);
$last = end($tmp);
unset($tmp);
foreach ($path as $x => $crumb) {
$title = ucwords(str_replace(array('.php', '_'), array('', ' '), $crumb));
if ($x == 1){
$breadcrumbs[] = "<a href=\"$base_url$crumb\">$title</a>";
}elseif ($x > 1 && $x < $last){
$tmp = "<a href=\"$base_url";
for($i = 1; $i <= $x; $i++){
$tmp .= $path[$i] . '/';
}
$tmp .= "\">$title</a>";
$breadcrumbs[] = $tmp;
unset($tmp);
}else{
$breadcrumbs[] = "$title";
}
}
return implode($separator, $breadcrumbs);
}
echo breadcrumbs();
?>
答案 0 :(得分:0)
只需扩展您拥有的内容:
$title = ucwords(str_replace(array('.php', '_', '-'), array('', ' ', ' '), $crumb));