19 declare(strict_types=1);
37 public function isTrue(
string $string): bool
39 if (!preg_match(
'/<[^>]+?>/', $string)) {
43 $error_state = libxml_use_internal_errors(
true);
44 libxml_clear_errors();
47 set_error_handler(
static function (
int $severity,
string $message,
string $file,
int $line):
void {
48 throw new ErrorException($message, $severity, $severity, $file, $line);
52 $import_succeeded = $dom->loadHTML($string);
54 $errors = libxml_get_errors();
55 libxml_clear_errors();
56 libxml_use_internal_errors($error_state);
70 RecursiveIteratorIterator::SELF_FIRST
72 foreach ($iter as $element) {
74 if (strtolower($element->nodeName) ===
'body') {
78 if ($element->nodeType === XML_ELEMENT_NODE) {
85 $errors = libxml_get_errors();
86 libxml_clear_errors();
87 libxml_use_internal_errors($error_state);
90 restore_error_handler();