xml error string in PHP

In this article I will explain how the xml_error_string() function can be used in PHP.
  • 2027

xml_error_string() function in PHP

  • The xml_error_string() function is used to get the XML parser error description.
  • The xml_error_string() function returns the error description on success.
  • The xml_error_string() function returns FALSE on failure.




  • errorcode errorcode is required parameter. it is specify for error code to use. The error code is the return value from the xml_get_error_code() function.

The following example show to how the xml_error_string() function can be used in PHP.



<h3 style="color: darkblue;">xml_error_string() function example in PHP</h3>


    $file = "xmltest.xml";

    $xml_parser = xml_parser_create();

    $fp = @fopen($file,'r');

    while ($data = fread($fp,4096))


    if (!xml_parse($xml_parser,$data,feof($fp)))


    die( print "ERROR: "

    . xml_error_string(xml_get_error_code($xml_parser))

    . "<br />"

    . "Line: "

    . xml_get_current_line_number($xml_parser)

    . "<br />"

    . "Column: "

    . xml_get_current_column_number($xml_parser)

    . "<br />");









You may also want to read these related articles here
Ask Your Question 
Got a programming related question? You may want to post your question here
© 2020 DotNetHeaven. All rights reserved.