PHP Dom problem, how to insert html code in a particular div

Posted by sala_7 on Stack Overflow See other posts from Stack Overflow or by sala_7
Published on 2010-06-05T11:33:45Z Indexed on 2010/06/05 11:42 UTC
Read the original article Hit count: 186

Filed under:
|
|
|

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();

© Stack Overflow or respective owner

Related posts about php

Related posts about dom