PHP DOMNode实体和nodeValue [英] PHP DOMNode entities and nodeValue
问题描述
当获取nodeValue中具有实体的DOMNode对象的nodeValue(即a& gt)时,将实体转换为可打印字符(即>)
有人知道有什么办法让它保持为一个实体,当它转换成意想不到的东西时,真的会混淆字符串比较。
以下代码重现您将注意到的问题,转储的长度为3时应为6。
<?php
$ xml ='<?xml version =1.0?>
< root>
< element>& gt< / element>
< / root>';
$ a = new DOMDocument();
$ a-> loadXML($ xml);
var_dump($ a-> childNodes-> item(0) - > nodeValue);
loadXML() code>采用
不应该这样做。但是,根据,libxml似乎出现了一个bug,这个错误报告 选项
参数,其中一个选项是 LIBXML_NOENT ,这样可以将实体转换为其表示,所以默认情况下,$ code> loadXML()
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);
loadXML()
takes an options
argument, and one of the options is LIBXML_NOENT, which enables converting entities to their representations, so by default loadXML()
shouldn't do so. However, there appears to be a bug in libxml that causes it to happen all the time, according to this bug report
这篇关于PHP DOMNode实体和nodeValue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!