PHP code example of petarmarj / google-sitemap-parser

1. Go to this page and download the library: Download petarmarj/google-sitemap-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

petarmarj / google-sitemap-parser example snippets



\petarmarj\GoogleSitemapParser;
use \petarmarj\Exceptions\GoogleSitemapParserException;

try {
    $posts = (new GoogleSitemapParser('https://www.watson.ch/api/1.0/feed/googlesitemap.xml'))->parse();
    foreach ($posts as $post) {
        print $post . '<br>';
    }
} catch (GoogleSitemapParserException $e) {
    print $e->getMessage();
}


\petarmarj\GoogleSitemapParser;
use \petarmarj\Exceptions\GoogleSitemapParserException;

try {
    $posts = (new GoogleSitemapParser('https://www.watson.ch/robots.txt'))->parseFromRobots();
    foreach ($posts as $post) {
        print $post . '<br>';
    }
} catch (GoogleSitemapParserException $e) {
    print $e->getMessage();
}


\petarmarj\GoogleSitemapParser;
use \petarmarj\Exceptions\GoogleSitemapParserException;

try {
    $posts = (new GoogleSitemapParser('https://www.watson.ch/robots.txt', true))->parseFromRobots();
    foreach ($posts as $post => $priority) {
        print 'URL: '. $post . '<br>Priority: '. $priority . '<hr>';
    }
} catch (GoogleSitemapParserException $e) {
    print $e->getMessage();
}


\petarmarj\GoogleSitemapParser;
use \petarmarj\Exceptions\GoogleSitemapParserException;

try {
    $posts = (new GoogleSitemapParser('http://www.sainsburys.co.uk/wcsstore/robots/sitemap_10151_4.xml.gz'))->parseCompressed();
    foreach ($posts as $post => $priority) {
        print 'URL: '. $post . '<br>Priority: '. $priority . '<hr>';
    }
} catch (GoogleSitemapParserException $e) {
    print $e->getMessage();
}