19declare(strict_types=1);
26use RecursiveIteratorIterator;
35 public function isValid(): bool
37 if (!preg_match(
'/<[^>]+?>/', $this->text)) {
42 $dom =
new DOMDocument();
43 if (!$dom->loadHTML($this->text)) {
47 $iter =
new RecursiveIteratorIterator(
49 RecursiveIteratorIterator::SELF_FIRST
51 foreach ($iter as $element) {
53 if (strtolower((
string) $element->nodeName) ===
'body') {
57 if ($element->nodeType === XML_ELEMENT_NODE) {
61 }
catch (Exception | Throwable) {
__construct(private string $text)
Class ilHtmlDomNodeIterator.