Dom\HTMLDocument::createFromString
PHP function
Edit on GitHub ✎
(PHP 8 >= 8.4.0)
Parses an HTML document from a string
Description
Dom\HTMLDocument::createFromString(string $source, int $options = 0, string|null $overrideEncoding = null): Dom\HTMLDocument
Parses an HTML document from a string, according to the living standard.
Parameters
sourceThe string containing the HTML to parse.
optionsOptions
overrideEncodingEncoding
Return Values
The parsed document as an Dom\HTMLDocument instance.
Errors/Exceptions
Examples
Dom\HTMLDocument::createFromString example
Parses a sample document.
php
<?php
$dom = Dom\HTMLDocument::createFromString(<<<'HTML'
<html>
<body>
<p>Hello, world!</p>
</body>
</html>
HTML);
echo $dom->saveHtml();
?>The above example will output:
output
<!DOCTYPE html><html><head></head><body>
<p>Hello, world!</p>
</body></html>Whitespace
See Also
Dom\HTMLDocument::createEmptyDom\HTMLDocument::createFromFile