我有以下问题,我在数组中生成了站点地图的网址。所以数组有 60000 个条目。谷歌希望我创建 2 个站点地图,因为每个站点地图的限制为 50000 个条目。
我怎样才能用 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);
} …Run Code Online (Sandbox Code Playgroud)