在PHP中创建多个站点地图
我有以下问题,我生成了一个数组中的站点地图URL。因此,该数组有60000个条目。谷歌想让我创建两个网站地图,因为每个网站地图最多只能有50000个条目 如何使用php实现这一点?我试过了,但是在循环停止并在另一个文件中输入其他数据时遇到了问题。这是我的密码在PHP中创建多个站点地图,php,sitemap,Php,Sitemap,我有以下问题,我生成了一个数组中的站点地图URL。因此,该数组有60000个条目。谷歌想让我创建两个网站地图,因为每个网站地图最多只能有50000个条目 如何使用php实现这一点?我试过了,但是在循环停止并在另一个文件中输入其他数据时遇到了问题。这是我的密码 // $data is array with the urls $count_array = count($data); $maxlinksinsitemap = 50000; $numbersofsitemap = ceil($count
// $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);
}
/$data是带有URL的数组
$count_array=count($data);
$maxlinksinsitemap=50000;
$numbersofsitemap=ceil($count\u数组/$maxlinksinsitemap);
因为($i=1;$i是你的朋友:
$data = array_chunk($data, 50000);
foreach ($data as $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 as $url)
{
$creat = "<url>\n";
$creat .= "<loc>" . $url . "</loc>\n";
$creat .= "<priority>1.00</priority>\n";
$creat .= "</url>\n";
fwrite($createfile, $creat);
}
fclose($createfile);
}
$data=array\u chunk($data,50000);
foreach($key=>$value形式的数据)
{
$cfile='sitemap_u200;'.$i.'.xml';
$createfile=fopen($cfile,'w');
fwrite($createfile,“\n”);
fwrite($createfile,“\n”);
foreach($url的值)
{
$creat=“\n”;
$creat.=''.$url.\n“;
$creat.=“1.00\n”;
$creat.=“\n”;
fwrite($createfile,$create);
}
fclose($createfile);
}
使用不同数量的现成站点地图。@AlixAxel:如果不在阵列中加载所有数据,我如何使用它?我有5 mil条记录,在阵列中加载所有数据可能会耗尽我的内存。
$data = array_chunk($data, 50000);
foreach ($data as $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 as $url)
{
$creat = "<url>\n";
$creat .= "<loc>" . $url . "</loc>\n";
$creat .= "<priority>1.00</priority>\n";
$creat .= "</url>\n";
fwrite($createfile, $creat);
}
fclose($createfile);
}