DOMDocument :: loadHTML错误 [英] DOMDocument::loadHTML error

查看:1654
本文介绍了DOMDocument :: loadHTML错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我构建了一个脚本,将页面上的所有css合并在一起,以便在我的cms中使用它。



警告 >:DOMDocument :: loadHTML()
[domdocument.loadhtml]:实体中的标题标题无效,行中有10行:
css.php on line 26 b>警告:
DOMDocument :: loadHTML()[domdocument.loadhtml]:在
中标记nav无效实体,行:10 < b> css.php on line 26


警告:DOMDocument :: loadHTML()[domdocument.loadhtml ]:在
26

css.php 中标记
部分在实体中无效,行:22 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: :__构造();
$ 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;
}
返回新的ArrayIterator($ array);


$ b $ foreach(新的样式表($ page)作为$ index => $ file){
$ css = file_get_contents($ file);
echo $ css;
}


解决方案

Header,Nav和Section是来自HTML5的元素。由于HTML5开发人员觉得难以记住公共和系统标识符,DocType声明只是:

 <!DOCTYPE html> ; 

换句话说,没有DTD需要检查,这将使DOM使用HTML4 Transitional DTD和这不包含这些元素,因此警告。



为了抑制警告,请将

  libxml_use_internal_errors(真); 

在调用 loadHTML 和 p>

  libxml_use_internal_errors(false); 

之后。

请使用 https://github.com/html5lib/html5lib-php


I build a script that combines all css on a page together to use it in my cms. It worked fine for a long time now i i get this error:


Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag header invalid in Entity, line: 10 in css.php on line 26

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag nav invalid in Entity, line: 10 in css.php on line 26

Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Tag section invalid in Entity, line: 22 in css.php on line 26

This is the php script

This is my code:

<?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;
}

解决方案

Header, Nav and Section are elements from HTML5. Because HTML5 developers felt it is too difficult to remember Public and System Identifiers, the DocType declaration is just:

<!DOCTYPE html>

In other words, there is no DTD to check, which will make DOM use the HTML4 Transitional DTD and that doesnt contain those elements, hence the Warnings.

To surpress the Warnings, put

libxml_use_internal_errors(true);

before the call to loadHTML and

libxml_use_internal_errors(false);

after it.

An alternative would be to use https://github.com/html5lib/html5lib-php.

这篇关于DOMDocument :: loadHTML错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆