php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67901 getElementsByTagname('link') does not work
Submitted: 2014-08-25 13:37 UTC Modified: 2014-08-25 21:36 UTC
From: noxtras at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.4.32 OS: Centos
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: noxtras at gmail dot com
New email:
PHP Version: OS:

 

 [2014-08-25 13:37 UTC] noxtras at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/domdocument.getelementsbytagname
---
There is a difference between
$node->getElementsByTagname("link")->item(0)->textContent
and 
$node->getElementsByTagname('link')->item(0)->textContent

the second one returns am empty string!

Test script:
---------------
$xml = file_get_contents('http://feeds.bbci.co.uk/news/uk/rss.xml?edition=uk');
$dom = new domDocument;
$dom->loadXML($xml);  
$dom->preserveWhiteSpace = false;
$items = $dom->getElementsByTagname('item');
foreach ($items as $k=>$node) {	
 //this works
    echo '<br>link: ' . $node->getElementsByTagname("link")->item(0)->textContent;
 //this does NOT work (returns empty string
    echo '<br>link: ' . $node->getElementsByTagname('link')->item(0)->textContent;
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-25 21:36 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-08-25 21:36 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

I can assure you that the quoting style makes absolutely no difference between 'link' and "link". Maybe you're using a variable instead of a literal value?
Keep checking your code for bugs.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Sep 19 20:01:33 2020 UTC