Using PHP I'm attempting to take an HTML string passed from a WYSIWYG editor and replace the children of an element inside of a preloaded HTML document with the new HTML.
So far I'm loading the document identifying the element I want to change by ID but the process to convert an HTML to something that can be placed inside a DOMElement is eluding me.
libxml_use_internal_errors(true);
$doc = new DOMDocument();
$doc->loadHTML($html);
$element = $doc->getElementById($item_id);
if(isset($element)){
//Remove the old children from the element
while($element->childNodes->length){
$element->removeChild($element->firstChild);
}
//Need to build the new children from $html_string and append to $element
}