// create a new DOMDocument object $doc = new DOMDocument(); // load the HTML content into the DOMDocument object $doc->loadHTML($html); // get the
` element is added as the first child of a `
// create a new DOMDocument object $doc = new DOMDocument(); // load the HTML content into the DOMDocument object $doc->loadHTML($html); // get thePackage library: The DOMNode class is part of the PHP core library, therefore no additional package or library is required.element by its ID $div = $doc->getElementById('my_div'); // create a newelement $new_p = $doc->createElement('p', 'New Paragraph'); // insert the new
element before the first child of the
element $div->insertBefore($new_p, $div->firstChild);