|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51235 getElementsByTagName always return an empty list
Submitted: 2010-03-08 13:27 UTC Modified: 2013-02-18 00:34 UTC
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: marsala dot marco at fastwebnet dot it Assigned:
Status: No Feedback Package: DOM XML related
PHP Version: 5.3.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
16 + 47 = ?
Subscribe to this entry?

 [2010-03-08 13:27 UTC] marsala dot marco at fastwebnet dot it
$document = new DOMDocument()->load(...);
$document->getElementsByTagName(<root element name>) works (returns list with one element).
getElementsByTagName(<non root element name>) always return an empty list. Examples on notes and on the web (some examples claimed to be working are prior the 5.3.2) are all  not working.

Tested on LAMP server PHP 5.2.8 AND on XAMPPLite WAMP PHP 5.3.1, both not working.

Test script:
$doc = new DOMDocument();
$faqs = $doc->getElementsByTagName("faq");
echo $faqs->length; // always 0

__xml/faq.xml is:

<?xml version="1.0" encoding="iso-8859-1"?>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-08 14:01 UTC]
-Status: Open +Status: Feedback
 [2010-03-08 14:01 UTC]
You sure no errors or warnings being thrown that aren't being shown? The example 
works fine for me using 5.3.2 and latests libxml2.
 [2010-10-26 19:48 UTC] shad dot cut dot this at shad dot net dot pl
Hello, in my script getElementsByTagName() return a empty list where a XML/HTML string used the char '-' int code 45. O zonk :/ 

before DOMDocument->loadHTML($html) I'm using a str_replace('-','__BAD_CHAR__',$html) and result I replace again to primary version.
 [2013-02-18 00:34 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Wed Nov 29 16:01:27 2023 UTC