PHP code example of roelofjan-elsinga / sitemap-generator

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

    

roelofjan-elsinga / sitemap-generator example snippets


use SitemapGenerator\SitemapGenerator;

$generator = new SitemapGenerator();

$generator->add('https://test-url.com/');

$xml_string = (string)$generator;
// OR
$xml_string = $generator->toXML();

print $xml_string;


$generator = new SitemapGenerator('https://test-url.com');

// or

$generator = new SitemapGenerator();

$generator->setDomain('https://test-url.com');

// or

$generator = SiteMapGenerator::boot('https://test-url.com');

$generator->add('/');

public function add(
    string $url, 
    $priority = 1, 
    string $last_modified = null, 
    string $change_frequency = 'weekly'
): SitemapGenerator

$generator->add('https://test-url.com/blog', 0.9, date('Y-m-d'), 'monthly');

// Or if you've set the domain earlier, this is even simpler:

$generator = SitemapGenerator::boot()->setDomain('https://test-url.com');

$generator->add('/blog', 0.9, date('Y-m-d'), 'monthly');