PHP面包屑数组,链接未满
对于面包屑,我使用以下代码:PHP面包屑数组,链接未满,php,breadcrumbs,Php,Breadcrumbs,对于面包屑,我使用以下代码: <?php class Breadcrumb { private $breadcrumb; private $separator = ' / '; private $domain = 'example.org'; public function build($array) { $breadcrumbs = array_merge(array('Home' => ''), $array); $cou
<?php
class Breadcrumb
{
private $breadcrumb;
private $separator = ' / ';
private $domain = 'example.org';
public function build($array)
{
$breadcrumbs = array_merge(array('Home' => ''), $array);
$count = 0;
foreach($breadcrumbs as $title => $link) {
$this->breadcrumb .= '
<span itemscope="" itemtype="https://schema.org/BreadcrumbList">
<a href="'.$this->domain. '/'.$link.'" itemprop="url">
<span itemprop="title">'.$title.'</span>
</a>
</span>';
$count++;
if($count !== count($breadcrumbs)) {
$this->breadcrumb .= $this->separator;
}
}
return $this->breadcrumb;
}
}
?>
我正在寻找这样的输出:example.org/about/more.php
多谢各位 您可以在循环过程中连接链接
$bclink = '';
foreach($breadcrumbs as $title => $link) {
if ($link != '') {
$bclink .= '/' . $link;
}
$this->breadcrumb .= '
<span itemscope="" itemtype="https://schema.org/BreadcrumbList">
<a href="'.$this->domain.$bclink.'" itemprop="url">
<span itemprop="title">'.$title.'</span>
</a>
</span>';
$count++;
if($count !== count($breadcrumbs)) {
$this->breadcrumb .= $this->separator;
}
}
$bclink='';
foreach($title=>$link的面包屑){
如果($link!=''){
$bclink.='/'.$link;
}
$this->breadcrumb.='
';
$count++;
如果($count!==count($breadcrumbs)){
$this->breadcrumb.=$this->separator;
}
}
您能用about/more.php替换more.php吗?是的,但我想看看除了键入以外是否还有其他解决方案?
Home: example.org
About: example.org/about
More: example.org/more.php
$bclink = '';
foreach($breadcrumbs as $title => $link) {
if ($link != '') {
$bclink .= '/' . $link;
}
$this->breadcrumb .= '
<span itemscope="" itemtype="https://schema.org/BreadcrumbList">
<a href="'.$this->domain.$bclink.'" itemprop="url">
<span itemprop="title">'.$title.'</span>
</a>
</span>';
$count++;
if($count !== count($breadcrumbs)) {
$this->breadcrumb .= $this->separator;
}
}