คือผมกำลังมีปัญหาเรื่องการสร้าง sitemap.xml ถ้าอยากจะสร้างเป็น muti sitemap
ข้อมูลอ่านจาก text ไฟล์ รับค่าจากฟอร์มมา ถ้าเกิน 50000 หมื่น url ให้สร้าง เป็นไฟล์ใหม่
ให้มันออกมาเป็น
sitemap1.xml
sitemap2.xml
sitemap3.xml
ต้องใช้เงื่อนไขยังไงครับ
โค้ดข้างล่างผมใช้ได้ปกติ แต่ถ้า เกิน 50000 ไฟล์ไปมันจะ add กับ gg ไม่ได้
ขอความกรุณาช่วยดูให้ทีครับ
<?php
$string = '<?xml version="1.0" encoding="UTF-8"?>';
$string .= '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
# main
$string .= '<url>';
$string .= '<loc>'.$domainname.'</loc>';
$string .= '<lastmod>'.date("Y-m-d").'</lastmod>';
$string .= '<changefreq>Monthly</changefreq>';
$string .= '<priority>0.8</priority>';
$string .= '</url>';
$num =0;
for($i=0;$i< $_POST['num'];$i++){
if($num<count($txtTitle)){
$products_name=$txtTitle[$num];
$products_name2=substr($txtTitle[$num],0,80)."...";
$ID=$txtID[$num];
$linkurl=seotitle($products_name2);
$allid=trim($txtID[$num]);
$link="$linkurl-$allid.html";
$string .= '<url>';
$string .= '<loc>'.$domainname.'/'.$link.'</loc>';
$string .= '<lastmod>'.date("Y-m-d").'</lastmod>';
$string .= '<changefreq>Monthly</changefreq>';
$string .= '<priority>0.8</priority>';
$string .= '</url>';
}
$num++;
}
$string .= '</urlset>';
// sitemap.xml Chmod 0777
$sitemap1 = "sitemap.xml";
$handle1 = fopen($sitemap1, 'w') or die("สร้างไฟล์ไม่สำเร็จ");
fwrite($handle1, $string);
fclose($handle1);
?>