View Full Version : Trying to create my own sitemaps...

11-11-2010, 08:22 PM
Hi there

I am trying to create my own sitemaps, so that they can be updated automatically.

The code I have found (from http://css-tricks.com) to scour all filenames on a webpage is as follows:

$html = file_get_contents('http://www.example.com');

$dom = new DOMDocument();

// grab all the on the page
$xpath = new DOMXPath($dom);
$hrefs = $xpath->evaluate("/html/body//a");

for ($i = 0; $i < $hrefs->length; $i++) {
$href = $hrefs->item($i);
$url = $href->getAttribute('href');
echo $url.'<br />';

This code works perfectly if I put a URL in the file_get_contents() that is not my site!
However, if I put the URL of my site in there (which is also where this code is hosted) I get no results! I have also tried putting /index.php there too - but to no avail!

Should I be using something else there instead?

I would really appreiate your views.

Many thanks