PHPackages                             sujanshresthanet/php-xml-sitemap-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sujanshresthanet/php-xml-sitemap-generator

ActivePhp[Utility &amp; Helpers](/categories/utility)

sujanshresthanet/php-xml-sitemap-generator
==========================================

PHP XML Sitemap Generator

v2.1.5(3y ago)18GPL-3.0+PHPPHP &gt;=5.3.10

Since Jun 2Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sujanshresthanet/php-xml-sitemap-generator)[ Packagist](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator)[ Docs](https://github.com/sujanshresthanet/php-xml-sitemap-generator)[ RSS](/packages/sujanshresthanet-php-xml-sitemap-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/e19a49435c29d983aec4311680d88669b06845a69e94242187e6cf49943c6552/687474703a2f2f706f7365722e707567782e6f72672f73756a616e73687265737468616e65742f7068702d786d6c2d736974656d61702d67656e657261746f722f76)](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator) [![Total Downloads](https://camo.githubusercontent.com/243b9d37beef55f1441bc2a56f456871e162908bd9cc03b3613072b572724c12/687474703a2f2f706f7365722e707567782e6f72672f73756a616e73687265737468616e65742f7068702d786d6c2d736974656d61702d67656e657261746f722f646f776e6c6f616473)](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator) [![Latest Unstable Version](https://camo.githubusercontent.com/116e67bcdb620ac371ca7ad3a4c300f3d2d768e81d691c7275edd5939fad3774/687474703a2f2f706f7365722e707567782e6f72672f73756a616e73687265737468616e65742f7068702d786d6c2d736974656d61702d67656e657261746f722f762f756e737461626c65)](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator) [![License](https://camo.githubusercontent.com/cbf4e91c8aa37432693526c75c23553a9cc98915478173774ee295b34d323dad/687474703a2f2f706f7365722e707567782e6f72672f73756a616e73687265737468616e65742f7068702d786d6c2d736974656d61702d67656e657261746f722f6c6963656e7365)](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator) [![PHP Version Require](https://camo.githubusercontent.com/e306d9e6b212b710888a6f6cf17bfe450db5da565b1edb33f1ef25d74d62f2bb/687474703a2f2f706f7365722e707567782e6f72672f73756a616e73687265737468616e65742f7068702d786d6c2d736974656d61702d67656e657261746f722f726571756972652f706870)](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator) [![Dependents](https://camo.githubusercontent.com/cefca544c897dd764beeff3b969af2ebf721436073e918baf9d549a99f1c77c4/687474703a2f2f706f7365722e707567782e6f72672f73756a616e73687265737468616e65742f7068702d786d6c2d736974656d61702d67656e657261746f722f646570656e64656e7473)](https://packagist.org/packages/sujanshresthanet/php-xml-sitemap-generator)

PHP Sitemap
===========

[](#php-sitemap)

PHP XML Sitemap Generator.

Installation via Composer
-------------------------

[](#installation-via-composer)

Add this to composer.json require block.

```
{
    "require": {
        "sujanshresthanet/php-xml-sitemap-generator": "2.*"
    }
}
```

Getting Started
---------------

[](#getting-started)

Create a sitemap object:

```
use SujanShrestha\Sitemap\Sitemap;

$sitemap = new Sitemap;
```

Add items to sitemap:

```
$sitemap->addUrlItem($url);
$sitemap->addUrlItem($url);
$sitemap->addUrlItem($url);
```

You can add some optional params.

```
use SujanShrestha\Sitemap\ChangeFreq;

$sitemap->addUrlItem($url, '1.0', ChangeFreq::DAILY, '2015-06-07 10:51:20');
$sitemap->addUrlItem($url, '0.7', ChangeFreq::WEEKLY, new \DateTime('2015-06-03 11:24:20'));
```

The arguments are `loc`, `priority`, `changefreq` and `lastmod`. See this table:

ParamsRequiredDescription`loc`requiredURL of the page. This URL must begin with the protocol (such as http) and end with a trailing slash, if your web server requires it. This value must be less than 2,048 characters.`priority`optionalThe date of last modification of the file. This date should be in [W3C Datetime format](http://www.w3.org/TR/NOTE-datetime). This format allows you to omit the time portion, if desired, and use YYYY-MM-DD.`changefreq`optionalHow frequently the page is likely to change. This value provides general information to search engines and may not correlate exactly to how often they crawl the page.`lastmod`optionalThe priority of this URL relative to other URLs on your site. Valid values range from 0.0 to 1.0. This value does not affect how your pages are compared to pages on other sites—it only lets the search engines know which pages you deem most important for the crawlers.See:

### Render it to XML:

[](#render-it-to-xml)

```
echo $sitemap->toString();

// OR

(string) $sitemap;
```

This is an example to send it as real sitemap for Google or other search engine:

```
header('Content-Type: application/xml');

echo $sitemap;

exit();
```

Output:

```

		http://sitemap.io

		http://sitemap.io/foo/bar/?flower=sakura&amp;fly=bird
		daily
		1.0
		2015-06-07T10:51:20+02:00

```

Arguments
---------

[](#arguments)

### loc

[](#loc)

The URL will be auto escaped. For example, the `&`, `>` will convert to `&amp;`, `&gt;`.

If you want to escape it yourself, set auto escape off:

```
$sitemap->setAutoEscape(false);
```

See:

### changefreq

[](#changefreq)

Valid values are:

```
ChangeFreq::ALWAYS;
ChangeFreq::HOURLY;
ChangeFreq::DAILY;
ChangeFreq::WEEKLY;
ChangeFreq::MONTHLY;
ChangeFreq::YEARLY;
ChangeFreq::NEVER;
```

The value `always` should be used to describe documents that change each time they are accessed.

The value `never` should be used to describe archived URLs.

Please note that the value of this tag is considered a hint and not a command. Even though search engine crawlers may consider this information when making decisions, they may crawl pages marked `hourly` less frequently than that, and they may crawl pages marked `yearly` more frequently than that.

Crawlers may periodically crawl pages marked `never` so that they can handle unexpected changes to those pages.

### priority

[](#priority)

The default priority of a page is `0.5`. Please note that the priority you assign to a page is not likely to influence the position of your URLs in a search engine's result pages. Search engines may use this information when selecting between URLs on the same site, so you can use this tag to increase the likelihood that your most important pages are present in a search index. Also, please note that assigning a high priority to all of the URLs on your site is not likely to help you. Since the priority is relative, it is only used to select between URLs on your site.

### lastmod

[](#lastmod)

Your date format will auto convert to [W3c Datetime format](http://www.w3.org/TR/NOTE-datetime). for example, if you send a string look like: `2015-06-07 10:51:20`, Sitemap object will auto convert it to `2015-06-07T10:51:20+02:00`.

This is an example to send it as real sitemap for Google or other search engine:

```
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();
```

You can set the format you want:

```
$sitemap->setDateFormat(\DateTime::ISO8601);

// OR

$sitemap->setDateFormat('Y-m-d');
```

Using Sitemap index files (to group multiple sitemap files)
-----------------------------------------------------------

[](#using-sitemap-index-files-to-group-multiple-sitemap-files)

```
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();
```

Output:

```

        http://domain.com/sitemap1.xml
        2015-06-07T10:51:20+02:00

		http://domain.com/sitemap2.xml
		2015-06-07T10:51:20+02:00

```

See:

More
----

[](#more)

- [Extending the Sitemaps protocol](http://www.sitemaps.org/protocol.html#extending)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

5

Last Release

1439d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/79e91bf7fe29065bcae86009f347546ddbb64441a466f88a36be87807d2413a5?d=identicon)[sujanshrestha](/maintainers/sujanshrestha)

---

Top Contributors

[![sujanshresthanet](https://avatars.githubusercontent.com/u/103834513?v=4)](https://github.com/sujanshresthanet "sujanshresthanet (11 commits)")

---

Tags

phpseositemapsitemap-generatorxml-sitemapphpgoogleSitemapseoxml-sitemap

### Embed Badge

![Health badge](/badges/sujanshresthanet-php-xml-sitemap-generator/health.svg)

```
[![Health](https://phpackages.com/badges/sujanshresthanet-php-xml-sitemap-generator/health.svg)](https://phpackages.com/packages/sujanshresthanet-php-xml-sitemap-generator)
```

###  Alternatives

[asika/sitemap

PHP Simple Sitemap Generator

1918.0k](/packages/asika-sitemap)[cyber-duck/silverstripe-seo

A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content

4351.1k](/packages/cyber-duck-silverstripe-seo)[fomvasss/laravel-meta-tags

A package to manage SEO (meta-tags, xml-fields, etc.)

3028.9k](/packages/fomvasss-laravel-meta-tags)[kphoen/sitemap-generator

Provides a way to create/generate a sitemap using Propel, Doctrine, etc.

1687.8k4](/packages/kphoen-sitemap-generator)[withcandour/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

13128.3k](/packages/withcandour-aardvark-seo)[tomatophp/filament-seo

Manage and generate SEO tags and integrate your website with Google SEO services

112.6k1](/packages/tomatophp-filament-seo)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
