Creating multiple Sitemaps in PHP -


i have following problem, generated urls sitemap, in array. array has 60000 entries. , google wants me create 2 sitemaps cause limit 50000 entries each sitemap.

how can make php? tried it, have problems loop stop , enter other data in other file. here code sofar.

// $data array urls $count_array = count($data); $maxlinksinsitemap = 50000; $numbersofsitemap = ceil($count_array / $maxlinksinsitemap);  for($i = 1; $i <= $numbersofsitemap; $i++) {     $cfile = "sitemap_" .$i . ".xml";     $createfile = fopen($cfile, 'w');     $creat = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";     $creat .= "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n";     $creat .= "xmlns:image=\"http://www.sitemaps.org/schemas/sitemap-image/1.1\"\n";     $creat .= "xmlns:video=\"http://www.sitemaps.org/schemas/sitemap-video/1.1\">\n";     $creat .= "<url>\n";     $creat .= "<loc>http://www.urltosite.com</loc>\n";     $creat .= "<priority>1.00</priority>\n";     $creat .= "</url>\n";       $creat .= "</urlset>";       fwrite($createfile, $creat);         fclose($createfile);   } 

i need dynamic solution,

thanks help.

array_chunk friend:

$data = array_chunk($data, 50000);  foreach ($data $key => $value) {     $cfile = 'sitemap_' . $i  . '.xml';     $createfile = fopen($cfile, 'w');      fwrite($createfile, "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");     fwrite($createfile, "<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\n");     fwrite($createfile, "xmlns:image=\"http://www.sitemaps.org/schemas/sitemap-image/1.1\"\n");     fwrite($createfile, "xmlns:video=\"http://www.sitemaps.org/schemas/sitemap-video/1.1\">\n");      foreach ($value $url)     {         $creat = "<url>\n";         $creat .= "<loc>" . $url . "</loc>\n";         $creat .= "<priority>1.00</priority>\n";         $creat .= "</url>\n";          fwrite($createfile, $creat);     }      fclose($createfile); } 

works variable number of sitemaps out of box.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -