php.net |  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mattsnowboard at gmail dot com
New email:
PHP Version: OS:

 

 [2012-01-13 16:18 UTC] mattsnowboard at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/domdocument.loadhtml
---
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:
---------------
<?php
libxml_use_internal_errors(true);
$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:
----------------
object(DOMNodeList)[3]

Actual result:
--------------
object(LibXMLError)[2]
  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

object(DOMNodeList)[3]

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-01-13 23:05 UTC] frozenfire@php.net
Automatic comment from SVN on behalf of frozenfire
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=322237
Log: Noted warnings produced by malformed HTML. Closes bug #60747.
 [2012-01-13 23:06 UTC] frozenfire@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: frozenfire
 [2012-01-13 23:06 UTC] frozenfire@php.net
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
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
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-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 09:01:26 2025 UTC