title: Creating an XML sitemap with PHP
body: <p>I'm trying to create a sitemap that will automatically update. I've done something similiar with my RSS feed, but this sitemap refuses to work. You can view it live at <a href="http://designdeluge.com/sitemap.xml" rel="noreferrer">http://designdeluge.com/sitemap.xml</a> I think the main problem is that its not recognizing the PHP code. Here's the full source:</p>
  
  <pre><code> &lt;?php 
  
  
  include 'includes/connection.php';
  
  header("Content-type: text/xml");
  
  echo '&lt;?xml version="1.0" encoding="UTF-8" ?&gt;';
  
  ?&gt;
  
  &lt;urlset xmlns="http://www.google.com/schemas/sitemap/0.84" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84 http://www.google.com/schemas/sitemap/0.84/sitemap.xsd"&gt;
  
      &lt;url&gt;
          &lt;loc&gt;http://designdeluge.com/&lt;/loc&gt;
          &lt;lastmod&gt;2010-04-20&lt;/lastmod&gt;
          &lt;changefreq&gt;weekly&lt;/changefreq&gt;
          &lt;priority&gt;1.00&lt;/priority&gt;
      &lt;/url&gt;
  
      &lt;url&gt;
          &lt;loc&gt;http://designdeluge.com/about.php&lt;/loc&gt;
          &lt;lastmod&gt;2010-04-20&lt;/lastmod&gt;
          &lt;changefreq&gt;never&lt;/changefreq&gt;
          &lt;priority&gt;0.5&lt;/priority&gt;
      &lt;/url&gt;
  
      &lt;?php
  
      $entries = mysql_query("SELECT * FROM Entries");
  
      while($row = mysql_fetch_assoc($entries)) {
      $title = stripslashes($row['title']);
      $date = date("Y-m-d", strtotime($row['timestamp']));
  
      echo "
  
      &lt;url&gt;
          &lt;loc&gt;http://designdeluge.com/".$title."&lt;/loc&gt;
          &lt;lastmod&gt;".$date."&lt;/lastmod&gt;
          &lt;changefreq&gt;never&lt;/changefreq&gt;
          &lt;priority&gt;0.8&lt;/priority&gt;
      &lt;/url&gt;";
  
   } ?&gt;
  
  &lt;/urlset&gt;
  </code></pre>
  
  <p>The problem is that the dynamic URL's (e.g. the ones pulled from the DB) aren't being generated and the sitemap won't validate. Thanks!</p>
  
  <p><strong>EDIT:</strong> Right now, I'm just trying to get the code itself working. I have it set up as a PHP file on my local testing server. The code above is being used. Right now, nothing displays nothing on screen or in the source. I'm thinking I made a syntax error, but I can't find anything. Any and all help is appreciated!</p>
  
  <p><strong>EDIT 2:</strong> Ok, I got it sorted out guys. Apparently, I had to echo the xml declaration with PHP. The final code is posted above. Thanks for your help!</p>