PHP writes an API that outputs something in XML format.
Now the direct display in the browser to report this error:
Error on line 4 at column 56:entityref:expecting '; '
To view the source code of the page, this line is:
Http://www.xxx.cn/index.php?id=5383&utm_source=57tuan
What's going on? How to solve?
Answer:
& Symbol, change to &, or directly with CDATA area ( )
The Firefox browser, Google Chrome browser, and most browsers display the XML file, not the source of the file, but the result of parsing the XML parser. However, when the "XML parser" encounters the character "&", it will take "&" as the beginning of an entity reference, and look for the end symbol of the entity reference ";", this is the problem that is encountered in this article.
In the XML document, there are 5 predefined entity references such as "&", namely "&", "<", ">", "" "," "".
Workaround One:
The entity reference is encoded and used, i.e.
Encode "&" as "&"
Encode "<" as "<"
Encode ">" as ">"
Encode "'" as "'"
Encode "" "" ""
Workaround Two:
In the markup CDATA, all tags, entity references are ignored and treated as raw character data by the "XML parser", CDATA in the following form:文本内容
Two points to be aware of using CDATA,
A: Because the end symbol of CDATA is "]]>", CDATA cannot contain "]]>",
Two: CDATA cannot be nested because all tags and entity references in CDATA are ignored.