In this short tutorial I will cover reading a Google/XML Sitemap and grabbing hold of each URL to use as you wish. This is amazingly easy to do:
Firstly we need to pass in the Sitemap URL. In the example we’re going to use GET since this is the most useful in my opinion.
<?php
$sitemap = $_GET['sitemap'];
// Some simple validation
if (!$myxml=simplexml_load_file($sitemap)){
echo ‘Unable to Access the Sitemap’;
}
// Loop through XML
foreach($myxml as $url)
{
$webpage_url = $url->loc;
// Do your thing here, store it in a database, run it against a function etc.
}
?>
This is ideal for reading a sitemap or RSS feed. Give it a try



















Leave a Reply