html-pretty-min icon indicating copy to clipboard operation
html-pretty-min copied to clipboard

DOMDocument::loadHTML(): Tag article invalid in Entity

Open Odepax opened this issue 10 years ago • 9 comments

Encountering unexpected error while parsing HTML5 tags:

DOMDocument::loadHTML(): Tag article invalid in Entity, line: 7
D:\...\Pasap\vendor\wa72\html-pretty-min\PrettyMin.php:76

Here is the code I'm trying to minify, https://validator.w3.org says it's valid:

<!DOCTYPE html><html lang="en">
    <head>
        <meta charset="UTF-8"/>
        <title>Document</title>
    </head>
    <body>
        <article class="News"> <!-- It blocks here -->
    <h1 class="title">We are Amazing</h1>
    <div class="about">
        <em>
            By Me,
            At 12-12-12     </em>
    </div>
    <div class="content">


                <p>
                    Lorem ipsum dolor sit amet, consectetur adipisicing elit.
                    Atque, consequatur cum iste laudantium libero magni maxime
                    minima mollitia quos. At earum nostrum pariatur. Amet, at
                    fugiat incidunt officia possimus vel?
                </p>
                </div>
</article>

    </body>
</html>

It seems to be a known problem: http://stackoverflow.com/questions/6090667/php-domdocument-errors-warnings-on-html5-tags

Odepax avatar Aug 04 '16 18:08 Odepax

$dom = new domDocument; libxml_use_internal_errors(true); // load the html into the object $dom->loadHTML($url);

behrouz-azand avatar Jan 08 '18 19:01 behrouz-azand

@$dom->loadHTML($url); works for me

berramou avatar May 14 '18 15:05 berramou

@$dom->loadHTML($url); works for me

why does this work? can somebody explain what that @ does at the beginning of the line, and why the downvotes?

ecairol avatar Feb 04 '20 20:02 ecairol

@ will disable error reporting

fri3ndly avatar Feb 19 '20 14:02 fri3ndly

@$dom->loadHTML($url); works for me

why does this work? can somebody explain what that @ does at the beginning of the line, and why the downvotes?

hides errors and super not recommended

marcaum54 avatar Apr 03 '20 11:04 marcaum54

In PHP the @ symbol ignores error. See

https://www.php.net/manual/en/language.operators.errorcontrol.php

tankfairies avatar Apr 10 '20 11:04 tankfairies

$dom->loadHtml($id);
work for me ( in Laravel 8.*)

webcomsco avatar Feb 07 '21 20:02 webcomsco

HTML5 is not supported by libxml2, therefore any HTML5 tag will fail. You can use (Since Libxml 2.6.0) the LIBXML_NOERROR flag to not get these errors, but in any way when you disable error reporting or suppress it, you will not receive errors for malformatted content.

$dom->loadHtml($id, LIBXML_NOERROR);

golddragon007 avatar Apr 11 '22 10:04 golddragon007

HTML5 is not supported by libxml2, therefore any HTML5 tag will fail. You can use (Since Libxml 2.6.0) the LIBXML_NOERROR flag to not get these errors, but in any way when you disable error reporting or suppress it, you will not receive errors for malformatted content.

$dom->loadHtml($id, LIBXML_NOERROR);

Thanks, work for me!

ynfantes avatar Jan 21 '23 16:01 ynfantes