(PHP 8 >= 8.4.0)
Dom\HTMLDocument::createFromString — Analiza un documento HTML a partir de un string
$source
, int $options
= 0, ?string $overrideEncoding
= null
): Dom\HTMLDocumentAnaliza un documento HTML a partir de un string, según la norma vigente.
source
options
Bitwise OR
of the libxml option constants.
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.
overrideEncoding
El documento analizado en forma de una instancia de Dom\HTMLDocument.
options
contains an invalid option.
overrideEncoding
is an unknown encoding.
Ejemplo #1 Ejemplo de Dom\HTMLDocument::createFromString()
Analiza un documento de ejemplo.
<?php
$dom = Dom\HTMLDocument::createFromString(<<<'HTML'
<!DOCTYPE html>
<html>
<body>
<p>Hello, world!</p>
</body>
</html>
HTML);
echo $dom->saveHtml();
?>
El resultado del ejemplo sería:
<!DOCTYPE html><html><head></head><body> <p>Hello, world!</p> </body></html>
Nota: Whitespace in the
html
andhead
tags is not considered significant and may lose formatting.