note 47907 modified in function.dom-domdocument-validate by aidan
| From: | aidan@php.net | Date: | Mon, 04 Jul 2005 09:50:55 +0000 |
| Subject: | note 47907 modified in function.dom-domdocument-validate by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-91396@lists.php.net to get a copy of this message | ||
This method throws E_NOTICE errors for any validation errors. If you'd rather store validation
errors in an array for gracious handling, you can use the code below.
<?php
/**
* Hold thrown errors statically
*/
function staticerror($errno, $errstr, $errfile, $errline, $errcontext, $ret = false)
{
static $errs = array();
if ($ret === true) {
return $errs;
}
$tag = 'DOMDocument::validate(): ';
$errs[] = str_replace($tag, '', $errstr);
}
// Load a document
$dom = new DOMDocument;
$dom->load('somefile');
// Set up error handling
set_error_handler('staticerror');
$old = ini_set('html_errors', false);
// Validate
$doc->validate();
// Restore error handling
ini_set('html_errors', $old);
restore_error_handler();
// Get errors
$errs = staticerror(null, null, null, null, null, true);
print_r($errs);
?>
--was--
This method throws E_NOTICE errors for any validation errors. If you'd rather store validation
errors in an array for gracious handling, you can use the code below.
<?php
/**
* Hold thrown errors statically
*/
function staticerror($errno, $errstr, $errfile, $errline, $errcontext, $ret = false)
{
static $errs = array();
if ($ret === true) {
return $errs;
}
$tag = 'DOMDocument::validate(): ';
$errs[] = str_replace($tag, '', $errstr);
}
// Load a document
$dom = new DOMDocument;
$dom->load('somefile');
// Set up error handling
set_error_handler('staticerror');
$old = ini_set('html_errors', false);
// Validate
$doc->validate();
// Restore error handling
ini_set('html_errors', $old);
restore_error_handler();
// Get errors
$errs = validatewarns(null, null, null, null, null, true);
print_r($errs);
?>
http://php.net/manual/en/function.dom-domdocument-validate.php