Skip to content

Instantly share code, notes, and snippets.

@n5i
Created November 10, 2012 13:52
Show Gist options
  • Save n5i/4051148 to your computer and use it in GitHub Desktop.
Save n5i/4051148 to your computer and use it in GitHub Desktop.
Checking if xml is valid
// The function checks if xml is valid
function is_valid_xml ( $xml ) {
if( empty( $xml ) ){
return null;
}
libxml_clear_errors();
libxml_use_internal_errors( true );
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML( $xml );
$errors = libxml_get_errors();
return empty( $errors );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment