阻止 PHP DOM 解码
PHP DOM 自动解码。例如 *
在创建 DOMElement 时被解码。有没有办法防止这种情况。一种解决方案是对文本进行预处理,然后对其进行后处理,但这看起来更像是一种黑客攻击。
示例代码:
$domDoc = new \DOMDocument();
$domEl = $domDoc->createElement('foo', 'text with * in it');
$domDoc->appendChild($domEl);
echo $domDoc->saveXML();
PHP DOM automatically decodes. Eg *
is decoded when creating a DOMElement. Is there a way to prevent this. One solution is to preprocess the text and afterwords postprocess it but this seems more like a hack.
example code:
$domDoc = new \DOMDocument();
$domEl = $domDoc->createElement('foo', 'text with * in it');
$domDoc->appendChild($domEl);
echo $domDoc->saveXML();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
DOMDocument,或者更确切地说,libxml,有一个布尔标志替代实体:
但是,这不适用于您的 ASCII 实体,因为它们是预定义的。有一个针对 PHP 5.1.4 的错误报告要求此操作,已标记为为“不是错误”,因为
另请参阅 http://xmlsoft.org/entities.html
DOMDocument, or rather libxml, has a boolean flag substituteEntities:
However, this won't work for your ASCII entities because they are predefined. There was a bug report asking for this for PHP 5.1.4, which is marked as "Not A Bug", because
Also see http://xmlsoft.org/entities.html