Example 1 — Read Messages for Known Codes
Pass a few XML_ERROR_* constants to xml_error_string() and print the message for each one.
<?php
$codes = [XML_ERROR_SYNTAX, XML_ERROR_NO_ELEMENTS, XML_ERROR_TAG_MISMATCH];
foreach ($codes as $code) {
echo $code, ": ", xml_error_string($code), PHP_EOL;
} How It Works
- The array holds three built-in error constants. Each one is just a number.
- foreach loops over the codes one by one.
- xml_error_string() looks up the text for each code.
- echo prints the number, a colon, and the message on one line.

