Home >Backend Development >PHP Tutorial >How Can I Save a DOMDocument's HTML Content in PHP Without the Default HTML, Body, and P Tags?
In your PHP function, you are attempting to save the contents of a DOMDocument without the enclosing , body, and
tags. However, saveXML() tends to add these wrappers when used with getElementsByTagName('p').
With PHP 5.4 and Libxml 2.6 or higher, you can utilize the loadHTML() function with additional options to prevent implied HTML elements and doctype:
$html->loadHTML($content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
Using these options, saveHTML() will not produce the unwanted wrappers.
The above is the detailed content of How Can I Save a DOMDocument's HTML Content in PHP Without the Default HTML, Body, and P Tags?. For more information, please follow other related articles on the PHP Chinese website!