我有以下问题,我生成了网站地图的URL,并将它们存储在一个数组中。因此,这个数组有60000个条目。而Google要求我创建2个网站地图,因为每个网站地图的限制是50000个条目。
请问如何通过PHP实现呢?我已经尝试过,但在循环停止并将其他数据输入到另一个文件时遇到了问题。以下是我的代码:
我需要一个动态解决方案,谢谢帮助。
请问如何通过PHP实现呢?我已经尝试过,但在循环停止并将其他数据输入到另一个文件时遇到了问题。以下是我的代码:
// $data is array with the 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);
}
我需要一个动态解决方案,谢谢帮助。