【发布时间】:2012-02-27 06:47:06
【问题描述】:
我构建了一个脚本,它将页面上的所有 css 组合在一起以在我的 cms 中使用它。它工作了很长时间现在我得到这个错误:
警告:DOMDocument::loadHTML() [domdocument.loadhtml]:实体中的标记标题无效,行:10 in css.php 第 26 行
警告: DOMDocument::loadHTML() [domdocument.loadhtml]:标签导航无效 实体,行:css.php 中的第 10 行 26
警告:DOMDocument::loadHTML() [domdocument. loadhtml]: 标签 实体中的部分无效,行:css.php 中的第 22 行 26
这是php脚本
这是我的代码:
<?php
header('Content-type: text/css');
include ('../global.php');
if ($usetpl == '1') {
$client = New client();
$tplname = $client->template();
$location = "../templates/$tplname/header.php";
$page = file_get_contents($location);
} else {
$page = file_get_contents('../index.php');
}
class StyleSheets extends DOMDocument implements IteratorAggregate
{
public function __construct ($source)
{
parent::__construct();
$this->loadHTML($source);
}
public function getIterator ()
{
static $array;
if (NULL === $array) {
$xp = new DOMXPath($this);
$expression = '//head/link[@rel="stylesheet"]/@href';
$array = array();
foreach ($xp->query($expression) as $node)
$array[] = $node->nodeValue;
}
return new ArrayIterator($array);
}
}
foreach (new StyleSheets($page) as $index => $file) {
$css = file_get_contents($file);
echo $css;
}
【问题讨论】:
-
这个问题已经在bugs.php.net/bug.php?id=60021 上报告了 PHP,这反过来又在底层 libxml2 中产生了一个功能请求:bugzilla.gnome.org/show_bug.cgi?id=761534
标签: php html domdocument