PHP code example of scarlet / sitemap-generator

1. Go to this page and download the library: Download scarlet/sitemap-generator 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/ */

    

scarlet / sitemap-generator example snippets




use Vendor\SitemapGenerator\SitemapGenerator;
use Vendor\SitemapGenerator\Exceptions\InvalidDataException;
use Vendor\SitemapGenerator\Exceptions\FileWriteException;
use Vendor\SitemapGenerator\Exceptions\UnsupportedFormatException;
use Vendor\SitemapGenerator\Exceptions\DuplicateUrlException;

$urls = [
    [
        'loc' => 'https://site.ru/',
        'lastmod' => '2020-12-14',
        'priority' => 1.0,
        'changefreq' => 'hourly'
    ]
];

try {
    $generator = new SitemapGenerator('xml', __DIR__ . '/sitemaps/sitemap.xml');
    $generator->generate($urls);
    echo "Карта сайта успешно создана!";
} catch (InvalidDataException | FileWriteException | UnsupportedFormatException | DuplicateUrlException $e) {
    echo "Ошибка: " . $e->getMessage();
}


sitemap-generator/
├── src/
│   ├── SitemapGenerator.php
│   ├── Interface/
│   │   ├── SitemapFormatterInterface.php
│   ├── Formatters/
│   │   ├── XmlSitemapFormatter.php
│   │   ├── CsvSitemapFormatter.php
│   │   ├── JsonSitemapFormatter.php
│   ├── Exceptions/
│   │   ├── DuplicateUrlException.php
│   │   ├── InvalidDataException.php
│   │   ├── FileWriteException.php
│   │   ├── UnsupportedFormatException.php
├── tests/
│   ├── SitemapGeneratorTest.php
│   ├── XmlSitemapFormatterTest.php
│   ├── CsvSitemapFormatterTest.php
│   ├── JsonSitemapFormatterTest.php
├── composer.json
├── README.md
├── .gitignore
├── LICENSE