PHP sitemap generator script

Posted by & filed under PHP.

Here’s a quick and basic script for generating a sitemap XML file for robots to index your site:

// $link is an array of URLs that you have pulled from your database or where ever!
$link = array_values(array_unique($link));// get rid of duplicates
$dt = date('Y-m-d\TH:i:s') . '+00:00';
$file = '<?xml version="1.0" encoding="UTF-8"?>
foreach ($link as $k => $url){
    $priority = ($k < 1) ? "1.0" : "0.8";
    $file .= "<url>
$file .= "</urlset>
echo file_put_contents('sitemap.xml', $file);// write to file

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>