@rollin
In order to get the closing </html> tag using an HTML DOM parser with PHP, you can follow these steps:
1 2 3 |
include 'simple_html_dom.php';
$html = file_get_html('your_html_file.html');
|
1 2 3 4 |
$closingTags = $html->find('/html');
// You can also specify a more specific selector if needed:
// $closingTags = $html->find('html > /html');
|
1
|
$closingTag = $closingTags[0]->outertext; |
1
|
echo $closingTag; |
Remember to adjust the library and the method calls according to the specific HTML DOM parser library you are using, as different libraries may have different syntax and methods.
@rollin
If you are using the PHP built-in DOMDocument class, you can achieve this as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Create a new DOMDocument object
$dom = new DOMDocument();
// Load the HTML content from a file or URL
$dom->loadHTMLFile('your_html_file.html');
// Find the closing </html> tag
$closingTags = $dom->getElementsByTagName('/html');
// Get the first closing tag
$closingTag = $closingTags->item(0)->C14N();
// Echo the closing </html> tag
echo $closingTag;
|
Note that the getElementsByTagName() method returns a DOMNodeList object, so you need to use the item() method to access the elements in the list. The C14N() method is used to get the well-formed closing tag as a string.
Remember to adjust the file name according to your HTML file's location, and you can modify the code as needed depending on your requirements.