PHP code example of sujanshresthanet / php-xml-sitemap-generator
1. Go to this page and download the library: Download sujanshresthanet/php-xml-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/ */
sujanshresthanet / php-xml-sitemap-generator example snippets
json
{
"janshresthanet/php-xml-sitemap-generator": "2.*"
}
}
php
use SujanShrestha\Sitemap\Sitemap;
$sitemap = new Sitemap;
php
$sitemap->addUrlItem($url);
$sitemap->addUrlItem($url);
$sitemap->addUrlItem($url);
php
echo $sitemap->toString();
// OR
(string) $sitemap;
php
header('Content-Type: application/xml');
echo $sitemap;
exit();
php
$sitemap->setAutoEscape(false);
php
ChangeFreq::ALWAYS;
ChangeFreq::HOURLY;
ChangeFreq::DAILY;
ChangeFreq::WEEKLY;
ChangeFreq::MONTHLY;
ChangeFreq::YEARLY;
ChangeFreq::NEVER;
php
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: text/xml");
header ("Content-Description:XML Sitemap" );
echo $sitemap;
exit();
php
use SujanShrestha\Sitemap\SitemapIndex;
$index = new SitemapIndex;
$index->addIndexItem('http://domain.com/sitemap1.xml', $lastmod1);
$index->addIndexItem('http://domain.com/sitemap2.xml', $lastmod2);
echo $index->toString();