Retain XML code when using PHP XMLWriter::writeElement

一个人想着一个人 提交于 2019-12-11 04:58:37

问题


I have a mySQL table with fields containing copy that's being turned into XML. Some of the copy in the mySQL fields has bold tags around the words:

<b>This will be bold</b>, this won't be.

However, when I come to build my XML document using XMLwriter, the copy ends up looking like this:

&lt;b&gt;This will be bold&lt;/b&gt;, this won't be

Can anyone advise me on how I can avoid character encoding for these tags?


回答1:


I am guessing your code needs to use XMLWriter::writeRaw instead of XMLWriter::text.

Note that this will only be a good solution if you are confident the content in the database will be proper XML. Otherwise, you will need to first run that content through a DOM parser like DOMDocument::loadXML with the DOMDocument::recover flag set, and then export the content with DOMDocument::saveXML and pass it to XMLWriter::writeRaw.




回答2:


Pass your copy through html_entity_decode(), like this:

echo html_entity_decode("&lt;b&gt;This will be bold&lt;/b&gt;, this won't be");


来源:https://stackoverflow.com/questions/12844599/retain-xml-code-when-using-php-xmlwriterwriteelement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!