Libxml Function in PHP

Introduction

The PHP libxml function is available as of PHP 5.1.0. It is used together with SimpleXMl, XSLT and DOM functions. Use of this function requires the libxml package.

In this article I describe the PHP libxml  functions libxml_clear_errors, libxml_get_errors, libxml_getlast_error, libxml_get_internal_errrors and libxml_set_streams_context.

PHP libxml_clear_errors() function

The PHP HTTP "libxml_clear_errors" function clears the libxml error buffer and this function returns no value.

Syntax

libxml_clear_errors()

Example

An example of the function is:
 

<?php

libxml_clear_errors();

?>
 

PHP libxml_get_errors() function

The PHP HTTP "libxml_get_errors" function retrieves an array of errors and this function returns an array with LibXMLError object if there are any errors in the buffer, or an empty array otherwise.

Syntax

libxml_get_errors()

Example

An example of the function is:
 

<?php

libxml_get_errors();

?>
 

PHP libxml_get_last_error() function

The PHP HTTP "libxml_get_last_error" function retrieves the last error from libxml and this function returns a LibXMLError object if there is any error in the buffer otherwise it returns false.

Syntax

libxml_get_last_error()

Example

An example of the function is:
 

<?php

libxml_get_last_error();

?>

 

PHP libxml_use_internal_errors() function

The PHP HTTP "libxml_use_internal_errors" function disables libxml errors and allows the user to fetch error information as needed and this function returns the previous value of user_errors.

Syntax

 

libxml_use_internal_errors(userErrors)

Parameter in libxml_use_internal_errors function

The parameter of the function is:

Parameter Description
userErrors It specifies if the user error handling should be enabled and by default it is false.

Example

An example of the function is:
 

<?php

libxml_use_internal_errors();

?>

PHP libxml_set_streams_context() function

The PHP HTTP "libxml_use_internal_errors" function sets the stream context for the next libxml document load or write and this function returns no value.

Syntax

 

libxml_use_internal_errors(StreamContext)

Parameter in libxml_set_streams_context function

The parameter of the function is:

Parameter Description
StreamContext It specifies the stream context resource.

Example

An example of the function is:
 

<?php

$options = array('http' => array('user_agent' => 'PHP libxml agent',));

$context = stream_context_create($options);

libxml_set_streams_context($context);

$doc = DOMDocument::load('http://www.c-sharpcorner.com/test.xml');

?>


Similar Articles