我正在使用一个小的模板引擎,并且我正在使用DOMDocument来解析页面。我的测试页,到目前为止是这样的:PHP DOMDocument剥离HTML标签
<?php echo 'this is some rendered PHP!
' ?>
Main column of content
而且我班的部分看起来像这样:
private function parse($tag, $attr = 'name')
{
$strict = 0;
/*** the array to return ***/
$out = array();
if($this->totalBlocks() > 0)
{
/*** a new dom object ***/
$dom = new domDocument;
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
/*** load the html into the object ***/
if($strict==1)
{
$dom->loadXML($this->file_contents);
}
else
{
$dom->loadHTML($this->file_contents);
}
/*** the tag by its tag name ***/
$content = $dom->getElementsByTagname($tag);
$i = 0;
foreach ($content as $item)
{
/*** add node value to the out array ***/
$out[$i]['name'] = $item->getAttribute($attr);
$out[$i]['value'] = $item->nodeValue;
$i++;
}
}
return $out;
}
我有工作,我想的方式,它抓住每一个上页面并注入它的内容到我的模板,但是,它剥离中的HTML标签,从而返回不
或标签以下内容:
this is some rendered PHP! Main column of content
我在这里做错了什么? :)谢谢