我有一个PHP函数,在html中呈现时会输出这样的引号。
onload="this.rel='stylesheet'"
我想要的是以下内容:
onload="this.rel='stylesheet'"
这是导致第一个例子发生的函数 - 有谁知道我怎么能解决这个问题?
public function get_css($opts, $index, $count)
{
$out = array();
$version = filemtime($_SERVER['DOCUMENT_ROOT'].'/assets/css/app.min.css');
$str = "this.rel='stylesheet'";
$out[] = $this->_single_tag('link', array(
'rel'=>'preload',
'as'=>'style',
'type'=>'text/css',
'href'=>'/assets/css/app.min.'.$version.'.css',
'onload'=>$str,
));
return implode("\n\t", $out)."\n";
}
以下是 _single_tag
的功能protected function _single_tag($tag=false, array $attrs)
{
if ($tag===false) return;
return PerchXMLTag::create($tag, 'single', $attrs);
}
答案 0 :(得分:1)
问题来自于get_css
方法,该方法对提供给它的值进行了一些HTML编码。
查看the Perch documentation似乎没有办法禁用此功能,因此我的建议是将public function get_css($opts, $index, $count)
{
$out = array();
$version = filemtime($_SERVER['DOCUMENT_ROOT'].'/assets/css/app.min.css');
$str = "this.rel='stylesheet'";
$out[] = "<link rel='preload' as='style' type='text/css' href='/assets/css/app.min.{$version}.css' onload='{$str}' />";
return implode("\n\t", $out)."\n";
}
函数中的代码替换为只输出原始HTML的代码:
<div class="left-col">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
Title 1
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
Content 1
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
Title 2
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
Content 2
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
Title 3
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
Content 3
</div>
</div>
</div>
</div>
</div>
<div class="right-col">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingOne">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
Title 1
</a>
</h4>
</div>
<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
<div class="panel-body">
Content 1
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingTwo">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
Title 2
</a>
</h4>
</div>
<div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo">
<div class="panel-body">
Content 2
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="headingThree">
<h4 class="panel-title">
<a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
Title 3
</a>
</h4>
</div>
<div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree">
<div class="panel-body">
Content 3
</div>
</div>
</div>
</div>
答案 1 :(得分:0)
public function get_css($opts, $index, $count)
{
$out = array();
$version = filemtime($_SERVER['DOCUMENT_ROOT'].'/assets/css/app.min.css');
$str = "this.rel=\"stylesheet\"";
$out[] = $this->_single_tag('link', array(
'rel'=>'preload',
'as'=>'style',
'type'=>'text/css',
'href'=>'/assets/css/app.min.'.$version.'.css',
'onload'=>$str,
));
return implode("\n\t", $out)."\n";
}
尝试一下。