title: Splitting into different files
body: <p>i have this code that creates a sitemap for my website. I wonder how i can make it split the sitemap into different files named &quot;sitemap1, sitemap2, sitemap3&quot; etc when reaching more then 50.000 entries ? currently it only makes one big sitemap on the server.</p>
  <pre><code>&lt;?
  
  $xmlfile = 'sitemap.xml';
  
  // this variable will contain the XML sitemap that will be saved in $xmlfile
  $xmlsitemap = '&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;urlset xmlns=&quot;http://www.sitemaps.org/schemas/sitemap/0.9&quot;&gt;';
  
  // Connection data (server_address, name, password, database_name)
  $hostdb = 'localhost';
  $userdb = 'user';
  $passdb = 'password';
  $namedb = 'db';
  
  try {
    // Connect and create the PDO object
    $conn = new PDO(&quot;mysql:host=$hostdb; dbname=$namedb&quot;, $userdb, $passdb);
    $conn-&gt;exec(&quot;SET CHARACTER SET utf8&quot;);      // Sets encoding UTF-8
  
    // Define and perform the SQL SELECT query
    $sql = &quot;SELECT `shortUrl` FROM `shorturl` ORDER BY `shorturl`.`id` DESC&quot;;
    $result = $conn-&gt;query($sql);
  
    // If the SQL query is succesfully performed ($result not false)
    if($result !== false) {
      // Parse the result set, and add the URL in the XML structure
      foreach($result as $row) {
        $xmlsitemap .= '
  &lt;br&gt;&lt;br&gt;
  Aurl&lt;br&gt;
  &lt;loc&gt;https://sptfy.com/'. $row['Url'] .'&lt;loc&gt;&lt;br&gt;
  &lt;changefreq&gt;monthly&lt;changefreq&gt;
  &lt;priority&gt;1&lt;priority&gt;&lt;br&gt;
  &lt;url&gt;
  
  ';
      }
    }
  
    $conn = null;        // Disconnect
  }
  catch(PDOException $e) {
    echo $e-&gt;getMessage();
  }
  
  $xmlsitemap .= '&lt;/urlset&gt;';
  file_put_contents($xmlfile, $xmlsitemap);          // saves the sitemap on server
  
  // outputs the sitemap (delete this instruction if you not want to display the sitemap in browser)
  echo $xmlsitemap;
  
  ?&gt;
  </code></pre>