Skip to content

Instantly share code, notes, and snippets.

@bradmarshall
Created June 14, 2018 18:44
Show Gist options
  • Save bradmarshall/cad7f4d5551664f005f411e168fddfb1 to your computer and use it in GitHub Desktop.
Save bradmarshall/cad7f4d5551664f005f411e168fddfb1 to your computer and use it in GitHub Desktop.
Read all URL's from XML sitemap file.
<?php
// Requires PHP DOM extension. Works with both local files and live ones on the web!
if(!isset($argv[1])) {
print("getSiteMapURLs.php error: This script takes one argument (the path of the site map to parse).".PHP_EOL);
die();
}
$urls = "";
$DomDocument = new DOMDocument();
$DomDocument->preserveWhiteSpace = false;
$DomDocument->load($argv[1]);
$DomNodeList = $DomDocument->getElementsByTagName('loc');
foreach($DomNodeList as $url) {
print($url->nodeValue.PHP_EOL);
}
//display 'em all
print($urls);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment