Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

libxml_use_internal_errors

Description

The libxml_use_internal_errors of libxml for PHP disables libxml errors and allows the user to fetch error information as needed.

Syntax

libxml_use_internal_errors(
    ?bool $use_errors = null
): bool

Parameters

use_errors

Enable (true) or disable (false) user error handling. Disabling will also clear any existing libxml errors.

Return

Returns the previous value of use_errors.

Examples

1 · void

<?

$return = libxml_use_internal_errors();

var_dump($return);

?>
bool(false)

2 · use_errors · false

<?

$use_errors = false;

$return = libxml_use_internal_errors($use_errors);

var_dump($return);

$return = libxml_use_internal_errors();

var_dump($return);

?>
bool(false)
bool(false)

3 · use_errors · true

<?

$use_errors = true;

$return = libxml_use_internal_errors($use_errors);

var_dump($return);

$return = libxml_use_internal_errors();

var_dump($return);

?>
bool(false)
bool(true)

4 · clear

<?

$use_errors = true;

libxml_use_internal_errors($use_errors);

$data =
<<<XML
<?xml version="1."?>
<books>
    <book>
        <titlex>title</title>
    </book>
</books>
XML;

$simplexml_load_string = simplexml_load_string($data);

if($simplexml_load_string === false)
{
    echo "before:\n";

    $libxml_get_errors = libxml_get_errors();

    foreach($libxml_get_errors as $value)
    {
        print_r($value);
    }

    //libxml_clear_errors();
    $use_errors = false;

    libxml_use_internal_errors($use_errors);

    echo "after:\n";

    $libxml_get_errors = libxml_get_errors();

    foreach($libxml_get_errors as $value)
    {
        print_r($value);
    }
}

?>
before:
LibXMLError Object
(
    [level] => 1
    [code] => 97
    [column] => 19
    [message] => Unsupported version '1.'

    [file] => 
    [line] => 1
)
LibXMLError Object
(
    [level] => 3
    [code] => 76
    [column] => 24
    [message] => Opening and ending tag mismatch: titlex line 4 and title

    [file] => 
    [line] => 4
)
after:
HomeMenu