Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

libxml_get_errors(3) [php man page]

LIBXML_GET_ERRORS(3)							 1						      LIBXML_GET_ERRORS(3)

libxml_get_errors - Retrieve array of errors

SYNOPSIS
array libxml_get_errors (void ) DESCRIPTION
Retrieve array of errors. RETURN VALUES
Returns an array with LibXMLError objects if there are any errors in the buffer, or an empty array otherwise. EXAMPLES
Example #1 A libxml_get_errors(3) example This example demonstrates how to build a simple libxml error handler. <?php libxml_use_internal_errors(true); $xmlstr = <<< XML <?xml version='1.0' standalone='yes'?> <movies> <movie> <titles>PHP: Behind the Parser</title> </movie> </movies> XML; $doc = simplexml_load_string($xmlstr); $xml = explode(" ", $xmlstr); if (!$doc) { $errors = libxml_get_errors(); foreach ($errors as $error) { echo display_xml_error($error, $xml); } libxml_clear_errors(); } function display_xml_error($error, $xml) { $return = $xml[$error->line - 1] . " "; $return .= str_repeat('-', $error->column) . "^ "; switch ($error->level) { case LIBXML_ERR_WARNING: $return .= "Warning $error->code: "; break; case LIBXML_ERR_ERROR: $return .= "Error $error->code: "; break; case LIBXML_ERR_FATAL: $return .= "Fatal Error $error->code: "; break; } $return .= trim($error->message) . " Line: $error->line" . " Column: $error->column"; if ($error->file) { $return .= " File: $error->file"; } return "$return -------------------------------------------- "; } ?> The above example will output: <titles>PHP: Behind the Parser</title> ----------------------------------------------^ Fatal Error 76: Opening and ending tag mismatch: titles line 4 and title Line: 4 Column: 46 -------------------------------------------- SEE ALSO
libxml_get_last_error(3), libxml_clear_errors(3). PHP Documentation Group LIBXML_GET_ERRORS(3)

Check Out this Related Man Page

SIMPLEXML_LOAD_STRING(3)						 1						  SIMPLEXML_LOAD_STRING(3)

simplexml_load_string - Interprets a string of XML into an object

SYNOPSIS
SimpleXMLElement simplexml_load_string (string $data, [string $class_name = "SimpleXMLElement"], [int $options], [string $ns = ""], [bool $is_prefix = false]) DESCRIPTION
Takes a well-formed XML string and returns it as an object. PARAMETERS
o $data - A well-formed XML string o $class_name - You may use this optional parameter so that simplexml_load_string(3) will return an object of the specified class. That class should extend the SimpleXMLElement class. o $options - Since PHP 5.1.0 and Libxml 2.6.0, you may also use the $options parameter to specify additional Libxml parameters. o $ns - Namespace prefix or URI. o $is_prefix - TRUE if $ns is a prefix, FALSE if it's a URI; defaults to FALSE. RETURN VALUES
Returns an object of class SimpleXMLElement with properties containing the data held within the xml document, or FALSE on failure. Warning This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function. ERRORS
/EXCEPTIONS Produces an E_WARNING error message for each error found in the XML data. Tip Use libxml_use_internal_errors(3) to suppress all XML errors, and libxml_get_errors(3) to iterate over them afterwards. EXAMPLES
Example #1 Interpret an XML string <?php $string = <<<XML <?xml version='1.0'?> <document> <title>Forty What?</title> <from>Joe</from> <to>Jane</to> <body> I know that's the answer -- but what's the question? </body> </document> XML; $xml = simplexml_load_string($string); print_r($xml); ?> The above example will output: SimpleXMLElement Object ( [title] => Forty What? [from] => Joe [to] => Jane [body] => I know that's the answer -- but what's the question? ) At this point, you can go about using $xml->body and such. SEE ALSO
simplexml_load_file(3), SimpleXMLElement::__construct, "Dealing with XML errors", libxml_use_internal_errors(3), "Basic SimpleXML usage". PHP Documentation Group SIMPLEXML_LOAD_STRING(3)
Man Page