I am trying to replace the html code inside the div 'resultsContainer' with the html of $response.
The result of my unsuccessful code is that the contents of 'resultsContainer' remain and the html of $response shows up on screen as text rather than being parsed as html.
Finally, I would like to inject the content of $response inside 'resultContainer' without having to create any new div, I need this: <div id='resultsContainer'>Html inside $response here...</div>
and NOT THIS: <div id='resultsContainer'><div>Html inside $response here...</div></div>
// Set Config
libxml_use_internal_errors(true);
$doc = new DomDocument();
$doc->strictErrorChecking = false;
$doc->validateOnParse = true;
// load the html page
$app = file_get_contents('index.php');
$doc->loadHTML($app);
// get the dynamic content
$response = file_get_contents('search.php'.$query);
$response = utf8_decode($response);
// add dynamic content to corresponding div
$node = $doc->createElement('div', $response);
$doc->getElementById('resultsContainer')->appendChild($node);
// echo html snapshot
echo $doc->saveHTML();