D
D
Danil2021-02-11 16:31:11
PHP
Danil, 2021-02-11 16:31:11

How to split a sitemap?

There are 50 thousand links, how to split them using php into separate sitemap files of 5 thousand each and create a main one in which all these files will be listed? You can even article if there is, I did not find anything

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
Danil, 2021-02-11
@Deletron247

$array= Array([0] => Array ( [name] =>  1699 ) ,[1] => Array ( [name] =>  1669 )) // масив намного длиней но структура однотипная
            $num = 0;
      $col = 5000;
      $val = $col;
      $sum = count($array);
      $cel = (intdiv($sum, $col) * $col);
      $ost = $sum - $cel;

      foreach($array as $i => $value):
          if ($i < $val){
                        print base_url("watch/".$value['name'].".html")."<br>";
          }else{
            print '<br>';
            print '<br>';
            if ($i >= $cel){
                $val = $val + $ost - 1;
            }else{
                $val = $val + $col;
            }
          }
    endforeach;

Nakidal seems to work, displays 50 links, then indents and repeats until the array runs out

N
no_one_safe, 2021-02-12
@no_one_safe

array_chunk

P
Puma Thailand, 2021-02-11
@opium

just make a cycle and pieces of 5k

A
Arris, 2021-02-13
@Arris

https://github.com/KarelWintersky/kwTools.SitemapG...
And don't reinvent the wheel. It has already been invented before you.

R
Rinat Haisman, 2022-01-28
@Rinat_Haisman

I recommend a personal service https://seospeciali.st/sitemap-split/
You can submit files with URLs in .txt, .xls or .xlsx formats or directly a sitemap in .xml format
Limit ~ up to 100k URLs

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question