|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #60747 DOMDocument loadHTML error with img close tag
Submitted: 2012-01-13 16:18 UTC Modified: 2012-01-13 23:06 UTC
From: mattsnowboard at gmail dot com Assigned: frozenfire (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.3.9 OS:
Private report: No CVE-ID: None
 [2012-01-13 16:18 UTC] mattsnowboard at gmail dot com
From manual page:
It says that this function should handle input that is not well-formed without 
error.  However, I have tried to parse a page (that I don't have control over) and 
found it will throw errors.  I have found that this can be avoided with: 
libxml_use_internal_errors(true).  If I remove the first line of the example 
below, I just get an error page, which I wouldn't expect from reading the 
documentation. I feel that this should be more clear in the documentation, but I'm 
assuming it's not a bug by itself.

Test script:
$document->loadHTML( '<img src="a.png" alt="a"></img>' );
foreach ( libxml_get_errors() as $error )
    var_dump( $error );
$imgs = $document->getElementsByTagName( 'img' );
var_dump( $imgs );

Expected result:

Actual result:
  public 'level' => int 2
  public 'code' => int 76
  public 'column' => int 32
  public 'message' => string 'Unexpected end tag : img
' (length=25)
  public 'file' => string '' (length=0)
  public 'line' => int 1



Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-13 23:05 UTC]
Automatic comment from SVN on behalf of frozenfire
Log: Noted warnings produced by malformed HTML. Closes bug #60747.
 [2012-01-13 23:06 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: frozenfire
 [2012-01-13 23:06 UTC]
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at

 For Windows:
Thank you for the report, and for helping us make PHP better.

While the documentation makes no mention of the functions *not* producing errors 
for malformed HTML, it isn't clear that it does. I've made note of that.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Fri Sep 22 14:01:24 2023 UTC