Here you go…
libxml_use_internal_errors(TRUE); $foo = @simplexml_load_string($bar); if ($foo === FALSE) { //Invalid XML } else { //$bar is XML }
If you want to display/log the errors…
foreach (libxml_get_errors() as $error) { //do something with $error->message } libxml_clear_errors();
Cheers 😀