我编写了一个脚本,将页面上的所有CSS组合在一起以便在我的CMS中使用。它工作得很好,但现在出现了以下错误:
警告: DOMDocument::loadHTML() [domdocument.loadhtml]: Entity中的header标记无效,行号:10位于css.php的第26行
警告: DOMDocument::loadHTML() [domdocument.loadhtml]: Entity中的nav标记无效,行号:10位于css.php的第26行
警告: DOMDocument::loadHTML() [domdocument.loadhtml]: Entity中的section标记无效,行号:22位于css.php的第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;
}