I'm working on a site that has about 3,000-4,000 dynamically generated pages, and I'm looking to update the XML sitemap. I've tried using online generators in the past, and they never seem to capture all the pages correctly, so I was just going to do something myself. Basically I have something like:
<?php
require('includes/connect.php');
$stmt = $mysqli->prepare("SELECT * FROM db_table ORDER BY column ASC");
$stmt->execute();
$stmt->bind_result($item1, $item2, $item3);
while($row = $stmt->fetch()) {
echo '<url><br />
<loc>http://www.example.com/section/'.$item1.'/'.$item2.'/'.$item3.'</loc>
<br />
<lastmod>2012-03-15</lastmod>
<br />
<changefreq>monthly</changefreq>
<br />
</url>
<br />
<br />';
}
$stmt->close();
$mysqli->close();
?>
Now short of having PHP write it to a text file, is there a way that I can force it to echo the actual XML tags (I just want to copy and paste it into my sitemap file)?
Add the following code at the beginning of your file:
header('Content-Type: text/plain');
By serving the response using this header, the browser will not try to parse it as XML, but show the full response as plain text.