XML Sitemap Generator using PHP — Phpflow.com

This PHP tutorial helps to create a dynamic XML sitemap generator using PHP. We’ll create a php script that helps to generate a website sitemap in xml format.

A sitemap is a mapping file that contains information about the URLs of the site’s pages and other necessary details.

What is sitemap

A sitemap, in its most basic form, is an XML file that contains a list of the URLs for a website along with additional metadata for each URL.? You can get more information for here.

For your website, make a legitimate sitemap and submit it to Google. It will aid its bots in indexing the site and achieving high rankings.

Online XML generator

Sitemap creation can be done online using the XML-Sitemaps Generator. It generates the best format for posting to search engines like Google, Bing, and others.

PHP Library

The XML sitemap is generated using the specified configuration parameters by an object-based PHP script. This is an open-source sitemap generator libs that automate creating a sitemap for Google crawling.


  • Multiple options for generating sitemaps
  • Option to only look through certain filetypes
  • Load client-side Javascript content when crawling
  • Parse all relative link types (// , # , ?) and more

Generate XML Sitemap Using PHP

How To Install Libs

How Import Libs

include "/path/to/sitemap-generator.php";

Generate XML Sitemap

$config = include("sitemap-config.php"); $smg = new SitemapGenerator($config); // Run the generator $smg->GenerateSitemap();

Full Source Code:

<?php include "sitemap-generator.php"; $config = include("sitemap-config.php"); $smg = new SitemapGenerator($config); // Run the generator $smg->GenerateSitemap(); ?>


Originally published at https://www.phpflow.com on August 16, 2022.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Parvez Alam

Hey, I am Parvez Alam. A software developer since 2009. I love learning and sharing knowledge. https://www.phpflow.com/