@@ 280-289 (lines=10) @@ | ||
277 | protected function createDOMDocument(string $html, $libXMLExtraOptions = null): \DOMDocument |
|
278 | { |
|
279 | // Remove content before <!DOCTYPE.*> because otherwise the DOMDocument can not handle the input. |
|
280 | if (\stripos($html, '<!DOCTYPE') !== false) { |
|
281 | /** @noinspection NestedPositiveIfStatementsInspection */ |
|
282 | if ( |
|
283 | \preg_match('/(^.*?)<!(?:DOCTYPE)(?: [^>]*)?>/sui', $html, $matches_before_doctype) |
|
284 | && |
|
285 | \trim($matches_before_doctype[1]) |
|
286 | ) { |
|
287 | $html = \str_replace($matches_before_doctype[1], '', $html); |
|
288 | } |
|
289 | } |
|
290 | ||
291 | if ($this->keepBrokenHtml) { |
|
292 | $html = $this->keepBrokenHtml(\trim($html)); |
|
@@ 347-356 (lines=10) @@ | ||
344 | $this->isDOMDocumentCreatedWithFakeEndScript = true; |
|
345 | } |
|
346 | ||
347 | if (\stripos($html, '</html>') !== false) { |
|
348 | /** @noinspection NestedPositiveIfStatementsInspection */ |
|
349 | if ( |
|
350 | \preg_match('/<\/html>(.*?)/suiU', $html, $matches_after_html) |
|
351 | && |
|
352 | \trim($matches_after_html[1]) |
|
353 | ) { |
|
354 | $html = \str_replace($matches_after_html[0], $matches_after_html[1] . '</html>', $html); |
|
355 | } |
|
356 | } |
|
357 | ||
358 | if (\strpos($html, '<script') !== false) { |
|
359 | $this->html5FallbackForScriptTags($html); |