(PHP 8 >= 8.4.0)
Dom\HTMLDocument::createFromString — Parses an HTML document from a string
$source, int $options = 0, ?string $overrideEncoding = null): Dom\HTMLDocumentParses an HTML document from a string, according to the living standard.
sourceoptions
Побітове
АБО констант опцій
libxml.
Dom\HTML_NO_DEFAULT_NS
to disable the use of the HTML namespace and the template element.
This should only be used if the implications are properly understood.
overrideEncodingThe parsed document as an Dom\HTMLDocument instance.
options contains an invalid option.
overrideEncoding is an unknown encoding.
Приклад #1 Dom\HTMLDocument::createFromString() example
Parses a sample document.
<?php
$dom = Dom\HTMLDocument::createFromString(<<<'HTML'
<!DOCTYPE html>
<html>
<body>
<p>Hello, world!</p>
</body>
</html>
HTML);
echo $dom->saveHtml();
?>Поданий вище приклад виведе:
<!DOCTYPE html><html><head></head><body>
<p>Hello, world!</p>
</body></html>
Зауваження: Whitespace in the
htmlandheadtags is not considered significant and may lose formatting.