时间:2021-07-01 10:21:17 帮助过:34人阅读
When using loadXML() to parse a string that contains entity references (e.g., ), be sure that those entity references are properly declared through the use of a DOCTYPE declaration; otherwise, loadXML() will not be able to interpret the string. Example: This is a non-breaking space. XML; $dd1 = new DOMDocument(); $dd1->loadXML($str); echo $dd1->saveXML(); ?> Given the above code, PHP will issue a Warning about the entity 'nbsp' not being properly declared. Also, the call to saveXML() will return nothing but a trimmed-down version of the original processing instruction...everything else is gone, and all because of the undeclared entity. Instead, explicitly declare the entity first: ]> This is a non-breaking space. XML; $dd2 = new DOMDocument(); $dd2->loadXML($str); echo $dd2->saveXML(); ?> Since the 'nbsp' entity is defined in the DOCTYPE, PHP no longer issues that Warning; the string is now well-formed, and loadXML() understands it perfectly. You can also use references to external DTDs in the same way (e.g., ), which is particularly important if you need to do this for many different documents with many different possible entities. Also, as a sidenote...entity references created by createEntityReference() do not need this kind of explicit declaration.
------解决方案--------------------
恭喜lz。~~
thanks ZT_king
------解决方案--------------------
< > 和 & 这三个不能出现