Load HTML from a string and create DOMDocument in PHP

Description

The following code shows how to load HTML from a string and create DOMDocument.

Example


// w w  w.j  a  v a 2  s.  com
<?php
$doc = new DOMDocument();
$doc->loadHTML("<html><body>Test<br></body></html>");
echo $doc->saveHTML();
?>

The code above generates the following result.





















Home »
  PHP Tutorial »
    XML »




DOM
SimpleXML
SimpleXMLElement
XML Parser