|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #73175 DOMDocument::saveHTML's void elements list is not updated
Submitted: 2016-09-26 09:42 UTC Modified: 2021-03-12 12:59 UTC
Avg. Score:4.3 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:2 (25.0%)
Same OS:1 (12.5%)
From: duhamelantoine1995 at gmail dot com Assigned: cmb (profile)
Status: Closed Package: DOM XML related
PHP Version: 7.0.11 OS: Debian 8
Private report: No CVE-ID: None
 [2016-09-26 09:42 UTC] duhamelantoine1995 at gmail dot com
The DOMDocument::saveHTML and DOMDocument::saveHTMLFile methods does not product valid HTML when using void elements introduced in HTML5.

The official HTML definition give a complete list of the void elements in HTML:

 > The following is a complete list of the void elements in HTML:
 > area, base, br, col, command, embed, hr, img, input, keygen, link, meta, param, source, track, wbr

In my tests (PHP 5&7, Debian 8 and Windows 10), PHP DOM render the following tags as non-void elements:
 - command
 - embed
 - keygen
 - source
 - track
 - wbr

Test script:
$implementation = new DOMImplementation;
$dom = $implementation->createDocument(
    $implementation->createDocumentType('html', null, null)
$dom->formatOutput = true;

$body = $dom->createElement('body');
$div = $dom->createElement('div');

$voidElem = ['area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input', 'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr',];

foreach ($voidElem as $tagName) {
echo $dom->saveHTML();

Expected result:
<!DOCTYPE html>

Actual result:
<!DOCTYPE html>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-12 12:59 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2021-03-12 12:59 UTC]
This is a known limitation of libxml2, and apparently there are no
plans to ever fix this.  There is not much we can do about it.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jul 29 07:01:24 2021 UTC