There are 24 items you can search

Simple XML Sitemap Generator PHP Script

A lightweight PHP script that turns a list of page URLs into a clean XML sitemap file.

This PHP script turns a plain list of page URLs into a basic XML sitemap.

Paste one URL per line, submit the form, and copy the generated XML into a file named sitemap.xml.

A sitemap helps search engines find the important pages on your site. This is useful for small websites, static pages, simple PHP sites, landing pages, and projects without a full CMS.

This version keeps things simple. No database, no API, no crawling, and no complicated setup.

<?php
declare(strict_types=1);

function h(string $value): string {
  return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
}

function clean_url(string $url): string {
  $url = trim($url);

  if ($url === '') {
    return '';
  }

  if (!filter_var($url, FILTER_VALIDATE_URL)) {
    return '';
  }

  $parts = parse_url($url);

  if (!$parts || empty($parts['scheme']) || empty($parts['host'])) {
    return '';
  }

  $scheme = strtolower((string)$parts['scheme']);

  if (!in_array($scheme, ['http', 'https'], true)) {
    return '';
  }

  return $url;
}

$input = trim((string)($_POST['urls'] ?? ''));
$urls = [];
$errors = [];
$sitemap = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $lines = preg_split('/\R+/', $input) ?: [];

  foreach ($lines as $line) {
    $url = clean_url($line);

    if ($url !== '') {
      $urls[] = $url;
    }
  }

  $urls = array_values(array_unique($urls));

  if (!$urls) {
    $errors[] = 'Enter at least one valid URL.';
  }

  if (!$errors) {
    $today = date('Y-m-d');

    $sitemap .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    $sitemap .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";

    foreach ($urls as $url) {
      $safeUrl = htmlspecialchars($url, ENT_XML1, 'UTF-8');

      $sitemap .= "  <url>\n";
      $sitemap .= "    <loc>" . $safeUrl . "</loc>\n";
      $sitemap .= "    <lastmod>" . $today . "</lastmod>\n";
      $sitemap .= "  </url>\n";
    }

    $sitemap .= "</urlset>\n";
  }
}
?>
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Simple XML Sitemap Generator</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    body {
      max-width: 760px;
      margin: 30px auto;
      padding: 0 16px;
      background: #fff;
      color: #111;
      font: 16px/1.5 Arial, sans-serif;
    }

    textarea {
      width: 100%;
      min-height: 180px;
      padding: 10px;
      box-sizing: border-box;
      font: 14px/1.5 Consolas, Monaco, monospace;
    }

    button {
      margin-top: 10px;
      padding: 10px 14px;
      border: 0;
      background: #111;
      color: #fff;
      cursor: pointer;
      font: inherit;
    }

    .error {
      padding: 10px;
      background: #ffdede;
      border: 1px solid #aa0000;
    }
  </style>
</head>
<body>

<h1>Simple XML Sitemap Generator</h1>

<p>
  Paste one URL per line. The script removes blanks, skips invalid URLs, removes duplicates, and generates a basic XML sitemap.
</p>

<form method="post" action="">
  <textarea
    name="urls"
    placeholder="https://example.com/&#10;https://example.com/about&#10;https://example.com/contact"
    required
  ><?= h($input); ?></textarea>

  <br>

  <button type="submit">Generate sitemap</button>
</form>

<?php if ($errors): ?>
  <div class="error">
    <?php foreach ($errors as $error): ?>
      <p><?= h($error); ?></p>
    <?php endforeach; ?>
  </div>
<?php endif; ?>

<?php if ($sitemap !== ''): ?>
  <h2>Your sitemap.xml</h2>

  <textarea readonly><?= h($sitemap); ?></textarea>

  <p>
    Copy this into a file named <strong>sitemap.xml</strong> and upload it to your website root.
  </p>
<?php endif; ?>

</body>
</html>

Save the script as something like sitemap-generator.php and upload it to your site.

Open the file in your browser, paste your page URLs, generate the XML, then copy the result into a file named sitemap.xml.

The finished sitemap should usually live here:

https://example.com/sitemap.xml
https://example.com/
https://example.com/about
https://example.com/contact
https://example.com/blog/post

Do not add private admin pages, login pages, duplicate URLs, search-result URLs, or pages blocked by robots.txt.

Also make sure your URLs use the same version of your site. Do not mix http and https or www and non-www unless you really use both.

Use this for small websites, hand-built PHP sites, static pages, simple tool directories, landing pages, or any project where you already know the URLs you want in the sitemap.

Skip this version if you need automatic crawling, image sitemaps, video sitemaps, news sitemaps, huge sitemap indexes, or automatic updates for thousands of URLs.