title: HTML DOM manipulation in PHP
body: <p>I wonder how I can manipulate the DOM tree using PHP?</p>
  
  <p>I have seen some answers with XML DOM that loads in a html file. But what if I don't need to load? What if have XML DOM scripts inside the document I want to manipulate?</p>
  
  <p>I have an example below that prints out all the folders. Fill in the blanks in your answers. I want to create div-elements with the folder's name as text node. The answer need to have some XML DOM scripts because I will create more elements than just one div-element in my website. And using for example echo is not practical, because you might insert an element inside the wrong element etc.</p>
  
  <pre><code>$sql = "
      SELECT name
      FROM folders
      WHERE profileId = '$profileId'
  ";
  $result = mysql_query($sql) or die('Error6: '.mysql_error());
  while($row = mysql_fetch_array($result)) {
  
  }
  </code></pre>