[](https://travis-ci.org/VIPnytt/SitemapParser)
[](https://scrutinizer-ci.com/g/VIPnytt/SitemapParser/?branch=master)
[](https://codeclimate.com/github/VIPnytt/SitemapParser)
[](https://codeclimate.com/github/VIPnytt/SitemapParser/coverage)
[](https://github.com/VIPnytt/SitemapParser/blob/master/LICENSE)
[](https://packagist.org/packages/VIPnytt/SitemapParser)
[](https://gitter.im/VIPnytt/SitemapParser)
# XML Sitemap parser
An easy-to-use PHP library to parse XML Sitemaps compliant with the [Sitemaps.org protocol](http://www.sitemaps.org/protocol.html).
The [Sitemaps.org](http://www.sitemaps.org/) protocol is the leading standard and is supported by Google, Bing, Yahoo, Ask and many others.
[](https://insight.sensiolabs.com/projects/2d3fbd49-66c4-4ab9-9007-aaeec6956d30)
## Features
- Basic parsing
- Recursive parsing
- String parsing
- Custom User-Agent string
- Proxy support
## Formats supported
- XML `.xml`
- Compressed XML `.xml.gz`
- Robots.txt rule sheet `robots.txt`
- Line separated text _(disabled by default)_
## Requirements:
- PHP [5.6 or 7.0+](http://php.net/supported-versions.php), alternatively [HHVM](http://hhvm.com)
- PHP extensions:
- [mbstring](http://php.net/manual/en/book.mbstring.php)
- [libxml](http://php.net/manual/en/book.libxml.php) _(enabled by default)_
- [SimpleXML](http://php.net/manual/en/book.simplexml.php) _(enabled by default)_
## Installation
The library is available for install via [Composer](https://getcomposer.org). Just add this to your `composer.json` file:
```json
{
"require": {
"vipnytt/sitemapparser": "^1.0"
}
}
```
Then run `composer update`.
## Getting Started
### Basic example
Returns an list of URLs only.
```php
use vipnytt\SitemapParser;
use vipnytt\SitemapParser\Exceptions\SitemapParserException;
try {
$parser = new SitemapParser();
$parser->parse('http://php.net/sitemap.xml');
foreach ($parser->getURLs() as $url => $tags) {
echo $url . '
';
}
} catch (SitemapParserException $e) {
echo $e->getMessage();
}
```
### Advanced
Returns all available tags, for both Sitemaps and URLs.
```php
use vipnytt\SitemapParser;
use vipnytt\SitemapParser\Exceptions\SitemapParserException;
try {
$parser = new SitemapParser('MyCustomUserAgent');
$parser->parse('http://php.net/sitemap.xml');
foreach ($parser->getSitemaps() as $url => $tags) {
echo 'Sitemap
';
echo 'URL: ' . $url . '
';
echo 'LastMod: ' . $tags['lastmod'] . '
';
echo '