PHP文件内容:在250000行代码之后创建新文件
我正在使用php脚本生成我的网站sitemap.xmlPHP文件内容:在250000行代码之后创建新文件,php,xml,seo,search-engine,Php,Xml,Seo,Search Engine,我正在使用php脚本生成我的网站sitemap.xml $conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb); $conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8 // Define and perform the SQL SELECT query $sql = "SELECT `title`,`id`,`
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
// Define and perform the SQL SELECT query
$sql = "SELECT `title`,`id`,`type`,`updated_at` FROM `titles`";
$result = $conn->query($sql);
// If the SQL query is succesfully performed ($result not false)
if($result !== false) {
// Parse the result set, and add the URL in the XML structure
foreach($result as $row) {
$xmlsitemap .= '<url>
<loc>/'. $type1 .'/'. $row['id'] .'-'. $string .'</loc>
<lastmod>'. $date1 .'</lastmod>
<priority>0.5</priority>
<changefreq>weekly</changefreq>
</url>';
}
}
$xmlsitemap .= '</urlset>';
file_put_contents($xmlfile, $xmlsitemap); // saves the sitemap on server
$conn=newpdo(“mysql:host=$hostdb;dbname=$namedb”、$userdb、$passdb);
$conn->exec(“设置字符集utf8”);//设置编码UTF-8
//定义并执行SQL选择查询
$sql=“选择`title`、`id`、`type`、`updated\`FROM`titles`”;
$result=$conn->query($sql);
//如果SQL查询成功执行($result not false)
如果($result!==false){
//解析结果集,并在XML结构中添加URL
foreach($结果为$行){
$xmlsitemap.='
/“.$type1.”/“.$row['id'].-“.$string.”
“.$date1。”
0.5
每周的
';
}
}
$xmlsitemap.='';
文件内容($xmlfile,$xmlsitemap);//在服务器上保存站点地图
目前我的sitemap.xml文件中有大约37000个URL
我知道网站地图有50000个URL的上限。在php中,有没有一种简单的方法可以告诉脚本在一定行数后创建第二个sitemap2.xml,例如每个url将有大约6行代码,因此我估计在达到250000行代码时应该创建新文件
另外,在服务器根目录中包含多个sitemap.xml文件以便搜索引擎机器人读取所有sitemap文件的最佳方式是什么?您需要将迭代器添加到
foreach
。如果迭代器>=50.000,则创建新文件