PHP libxml_get_errors() Function | Rookie Tutorial
Rookie Tutorial -- Learn not just technology, but also dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Bookmarks
PHP Tutorial
- PHP Tutorial
- PHP Intro
- PHP Installation
- PHP Syntax
- PHP Variables
- PHP echo/print
- PHP EOF(heredoc)
- PHP Data Types
- PHP Type Comparisons
- PHP Constants
- PHP Strings
- PHP Operators
- PHP If...Else
- PHP Switch
- PHP Arrays
- PHP Array Sorting
- PHP Superglobals
- PHP While Loops
- PHP For Loops
- PHP Functions
- PHP Magic Constants
- PHP Namespaces
- PHP OOP
- PHP Quiz
PHP Forms
- PHP Forms
- PHP Form Validation
- PHP Form - Required Fields
- PHP Form - Validate Email and URL
- PHP Complete Form Example
- PHP $_GET Variable
- PHP $_POST Variable
PHP Advanced Tutorial
- PHP Multidimensional Arrays
- PHP Date
- PHP Includes
- PHP Files
- PHP File Upload
- PHP Cookie
- PHP Session
- PHP E-mail
- PHP Secure E-mail
- PHP Error
- PHP Exception
- PHP Filters
- PHP Advanced Filters
- PHP JSON
PHP 7 New Features
PHP Database
- PHP MySQL Intro
- PHP MySQL Connection
- PHP MySQL Create Database
- PHP MySQL Create Table
- PHP MySQL Insert Data
- PHP MySQL Insert Multiple Data
- PHP MySQL Prepared Statements
PHP libxml_get_errors() Function
Definition and Usage
The libxml_get_errors() function is used to retrieve all errors generated during the process of loading or parsing XML documents. This function must be used in conjunction with libxml_use_internal_errors(). When libxml_use_internal_errors(TRUE) is set, libxml will suppress default error handling, allowing you to manually retrieve error information via libxml_get_errors().
Syntax
libxml_get_errors()
Parameters
This function has no parameters.
Return Value
Returns an array containing LibXMLError objects. If no errors are found, it returns an empty array.
Example
Example 1
Use libxml_get_errors() to get error information when loading an XML file fails:
<?php
libxml_use_internal_errors(true);
$xml = simplexml_load_file("test.xml");
if ($xml === false) {
$errors = libxml_get_errors();
foreach ($errors as $error) {
echo "Error: " . $error->code . "<br>";
echo "Message: " . $error->message . "<br>";
echo "Line: " . $error->line . "<br>";
echo "Column: " . $error->column . "<br>";
}
libxml_clear_errors();
}
?>
Example 2
Display all error details using print_r():
<?php
libxml_use_internal_errors(true);
$xml = simplexml_load_file("test.xml");
if ($xml === false) {
$errors = libxml_get_errors();
print_r($errors);
libxml_clear_errors();
}
?>
Possible output:
Array
(
=> LibXMLError Object
(
=> 2
=> 4
=> 1
=> Start tag expected, '<' not found
=> /path/to/test.xml
=> 1
)
)
Related Functions
- libxml_use_internal_errors() - Enable or disable internal error handling
- libxml_get_last_error() - Get the last error
- libxml_clear_errors() - Clear all error messages
For more information, please refer to the PHP libxml reference.
```
YouTip