PHP DOMNode entities and nodeValue
Posted
by Obsidian
on Stack Overflow
See other posts from Stack Overflow
or by Obsidian
Published on 2010-05-02T04:19:04Z
Indexed on
2010/05/02
4:27 UTC
Read the original article
Hit count: 369
When getting the nodeValue of a DOMNode object that has entities in the nodeValue (i.e. a & gt;) then it converts the entity into it's printable character (i.e. >)
Does anyone know of a way to get it to keep it as an entity, it really messes up string comparisons when it converts to something unexpected.
The following code reproduces the problem you will notice the length of the dump is 3 when it should be 6.
<?php
$xml='<?xml version="1.0"?>
<root>
<element>></element>
</root>';
$a=new DOMDocument();
$a->loadXML($xml);
var_dump($a->childNodes->item(0)->nodeValue);
© Stack Overflow or respective owner