|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #44762 DOMElement need a innerHTML
Submitted: 2008-04-17 14:40 UTC Modified: 2015-01-09 01:12 UTC
Avg. Score:4.4 ± 1.1
Reproduced:15 of 16 (93.8%)
Same Version:9 (60.0%)
Same OS:5 (33.3%)
From: xwisdom at yahoo dot com Assigned:
Status: Open Package: DOM XML related
PHP Version: * OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-04-17 14:40 UTC] xwisdom at yahoo dot com
I would like to request that a innerHTML property (or method) be added to DOMElement class. This would make it so much easier to retrieve and set the html or xml content of a node.

Right now we have to use fragments with several lines of to get the job done. It would be so much better to be able to do it in one line of code :)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2008-11-04 16:16 UTC] patrick at patricksmith dot org
In the meantime, here's a utility function that you may find helpful:

$innerHTML = '';
$elem = $doc->getElementById($elem_id);

// loop through all childNodes, getting html		
$children = $elem->childNodes;
foreach ($children as $child) {
    $tmp_doc = new DOMDocument();
    $innerHTML .= $tmp_doc->saveHTML();
 [2009-06-22 18:36 UTC] roly426 at gmail dot com
I was trying to use the above method to get the innerHTML in an HTML document but sine these functions are designed for XML, some HTML will get changed. Example, <br /> will get changed to <br>
 [2009-06-23 02:20 UTC] xwisdom at yahoo dot com
I really hope the PHP Developers will see the need for this feature and add it in.

You can try using this the DOM features found over at to see if they can assist you.
 [2011-04-08 18:15 UTC]
-Package: Feature/Change Request +Package: DOM XML related
 [2015-01-09 01:12 UTC]
-Operating System: Windows XP +Operating System: * -PHP Version: 5.2.5 +PHP Version: *
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Fri Jul 19 23:01:25 2019 UTC