PHP xml_error_string() Function

In this chapter you will learn:

  1. Description for PHP xml_error_string() Function
  2. Syntax for PHP xml_error_string() Function
  3. Parameter for PHP xml_error_string() Function
  4. Return for PHP xml_error_string() Function
  5. Example - gets the XML parser error description

Description

The xml_error_string() function gets the XML parser error description.

Syntax

PHP xml_error_string() Function has the following syntax.

xml_error_string(errorcode)

Parameter

ParameterIs RequiredDescription
errorcodeRequired.Error code to use. The error code is the return value from the xml_get_error_code() function

Return

This function returns the error description on success, or FALSE on failure.

Example

Gets the XML parser error description

Content for test.xml


<data>
   <missEndTag>
</data>

<?php//from ja  va  2  s . c o m

$xmlparser = xml_parser_create();

$fp = fopen('test.xml', 'r');

while ($xmldata = fread($fp, 1024)){
  if (!xml_parse($xmlparser,$xmldata,feof($fp))){
    print "ERROR: ";
    print xml_error_string(xml_get_error_code($xmlparser));
    print "\n";
    print "Line: ";
    print xml_get_current_line_number($xmlparser);
    print "\n";
    print "Column: ";
    print xml_get_current_column_number($xmlparser);
    print  "\n";
  }
}

xml_parser_free($xmlparser);
?>

Next chapter...

What you will learn in the next chapter:

  1. Description for PHP xml_get_current_byte_index() Function
  2. Syntax for PHP xml_get_current_byte_index() Function
  3. Parameter for PHP xml_get_current_byte_index() Function
  4. Return for PHP xml_get_current_byte_index() Function
  5. Example - gets the byte index for an XML parser