A Basic sitemap generator generated by scraping
This package is a sitemap generator which generates XML sitemap for any given website dynamically. It generates sitemap by scraping all links from webpages recursively. But I tried to make it efficient by reducing the number of loops in least possible value., (*1)
You can install the package using composer., (*2)
composer require ashfaq1701/sitemap-generator
After installation using composer require the composer autoload file., (*3)
require 'vendor/autoload.php';
After this follow the steps below,, (*4)
use Ashfaq1701\SitemapGenerator\SitemapGenerator; .... $sitemapGenerator = new SitemapGenerator($url, $path, $maximum); $sitemap->generateSitemap();
It will generate the sitemap xml file in the file passed in $path variable. The maximum number of url's in the sitemap will be the number passed in $maximum., (*5)
A typical call will be like,, (*6)
$sitemapGenerator = new SitemapGenerator('https://www.venturepact.com', '/home/user/sitemap.xml', 2000); $sitemap->generateSitemap();
The $path and $maximum parameters are not mandatory because they assume default values as $path='sitemap.xml' and $maximum=1000., (*7)
The generateSitemap() method not only writes the xml sitemap in the given directory but it also returns the sitemap XML as String. You can use this as following,, (*8)
$sitemapGenerator = new SitemapGenerator('https://www.venturepact.com', '/home/user/sitemap.xml', 2000); $sitemapText = $sitemap->generateSitemap(); echo $sitemapText;
If you have suggestions or need improvements please create issues or fork. Any improvements are more than welcome., (*9)