In PHP, xml_get_error_code() returns the number of the last error that happened on an XML parser.
When xml_parse() returns 0, something is wrong with the XML. This function tells you what kind of problem it was, and you can turn the number into text with xml_error_string().
Syntax
Call xml_get_error_code() with the values you need. Start with this line.
PHP
$code = xml_get_error_code($parser);
Call
What it does
xml_get_error_code($parser)
Returns the last error code for the parser.
xml_get_error_code($parser) === XML_ERROR_NONE
Checks that no error happened.
xml_error_string(xml_get_error_code($parser))
Turns the code into a message.
Call it right after xml_parse() returns 0. A value of 0, which is XML_ERROR_NONE, means there is no error.
Library declarations
PHP
xml_get_error_code(XMLParser $parser): int
Parameters
Parameter
Description
parser
Required. The XMLParser object created by xml_parser_create() or xml_parser_create_ns().
Return Value
Return Value
Description
int
The error code. 0 means no error. Compare it with the XML_ERROR_* constants.
PHP Examples
Example 1 — Read the Code After a Failed Parse
Parse XML with a wrong closing tag and look at the error code.