19declare(strict_types=1);
39 public function isValid(): bool
41 if (!preg_match(
'/<[^>]+?>/', $this->text)) {
46 set_error_handler(
static function (
int $severity,
string $message,
string $file,
int $line):
void {
47 throw new ErrorException(
$message, $severity, $severity, $file, $line);
52 $dom =
new DOMDocument();
53 $import_succeeded = $dom->loadHTML($this->text);
61 $iter =
new RecursiveIteratorIterator(
63 RecursiveIteratorIterator::SELF_FIRST
65 foreach ($iter as $element) {
67 if (strtolower($element->nodeName) ===
'body') {
71 if ($element->nodeType === XML_ELEMENT_NODE) {
77 }
catch (Throwable
$e) {
81 restore_error_handler();
87 $this->xmlErrorState = libxml_use_internal_errors(
true);
88 libxml_clear_errors();
93 $currentErrors = libxml_get_errors();
94 libxml_clear_errors();
96 $this->xmlErrors = $currentErrors;
103 libxml_use_internal_errors($this->xmlErrorState);
111 return array_filter($this->xmlErrors,
static function (LibXMLError $error):
bool {
Class ilHtmlDomNodeIterator.
Class ilTermsOfServiceDocumentsContainsHtmlValidator.
const LIBXML_CODE_HTML_UNKNOWN_TAG
__construct(string $text)