Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Create XML Sitemap Using PHP

Friday, Jan 27, 2017

Tags:- PHP

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL like when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site so that search engines can more intelligently crawl the site.So, in this tutorial we will show you how to create sitemap using PHP.You may also like create rss feed using PHP.

Create XML Sitemap Using PHP

To Create XML Sitemap It Takes Only One Step:-

  1. Make a PHP file to create sitemap

Step 1.Make a PHP file to create sitemap

We make a PHP file and save it with a name sitemap.php

// Sample Structure Of XML Sitemap
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="">
  <loc> </loc>

// Database Structure 
 'link' text NOT NULL,
 'date' text NOT NULL,


header('Content-type: application/xml');
$get_result=mysql_query("select * from post");

echo "<?xml version='1.0' encoding='UTF-8'?>"."\n";
echo "<urlset xmlns=''>"."\n";

echo "

 echo "<url>";
 echo "<loc>".$row['link']."</loc>";
 echo "<lastmod>".$row['date']."</lastmod>";
 echo "<changefreq>daily</changefreq>";
 echo "</url>";

echo "</urlset>";


In this step we create a database called 'post' and insert our post link and date created and then write proper header to display xml file in browser then we write structure of sitemap and get all the post link and date and insert in our sitemap after that we display the sitemap and copy all the text from browser and create a file 'sitemap.xml' and insert the copied text to it.You may also like read xml file using PHP.

That's all, this is how to create xml sitemap using PHP.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH