Dom\HTMLDocument::saveHtml
(PHP 8 >= 8.4.0)
Dom\HTMLDocument::saveHtml — Serializes the document as an HTML string
Description
Serializes the document as an HTML string.
Parameters
node
The node to serialize. If not provided, the entire document is serialized.
Return Values
The serialized HTML document string in the current document encoding.
Errors/Exceptions
-
Throws a Dom\DOMException with code
Dom\WRONG_DOCUMENT_ERRifnodeis from another document.
Examples
Example #1 Dom\HTMLDocument::saveHtml() example
Serializes a document to an HTML string.
<?php
$dom = Dom\HTMLDocument::createFromString('<!DOCTYPE html><p>Hello, world!</p>');
echo $dom->saveHtml();
?>The above example will output:
<!DOCTYPE html><html><head></head><body><p>Hello, world!</p></body></html>
See Also
- Dom\HTMLDocument::saveHtmlFile() - Serializes the document as an HTML file
- Dom\HTMLDocument::saveXml() - Serializes the document as an XML string
来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。
