撒拉嘿!酒肉穿肠过,久坐板凳上,要说不迈腿,肚子自然凸。
function sitemap() {
$domain = "https://domain.com";
$txtmap = "";
$listData = ["/","/admin","/demo","/test",];
foreach ($listData as $l){
$txtmap .= $domain.$l."\n";
}
try{
$fileUrl = 'sitemap.txt';
$txtfurl = fopen($fileUrl, "w");
fwrite($txtfurl, $txtmap);
fclose($txtfurl);
}catch (Exception $e){
return json(["code"=>400,"msg"=>"出错了"]);
}
return json(["code"=>200,"msg"=>"网站地图获取成功"]);
}
function sitemap() {
$domain = "https://domain.com";
$listData = ["/","/admin","/demo","/test",];
$xmlmap = '<?xml version="1.0" encoding="utf-8" ?>';
$xmlmap .="<urlset>";
foreach ($listData as $l){
$xmlmap .= "<url>";
$xmlmap .= "<loc>".$domain.$l."</loc>";
$xmlmap .= "<priority>1.0</priority>";
$xmlmap .= "<changefreq>daily</changefreq>";
$xmlmap .= "<lastmod>".date("Y-m-d")."</lastmod>";
$xmlmap .= "</url>";
}
$xmlmap .="</urlset>";
try{
$fileUrl = 'sitemap.xml';
$xmlfurl = fopen($fileUrl, "w");
fwrite($xmlfurl, $xmlmap);
fclose($xmlfurl);
}catch (Exception $e){
return json(["code"=>400,"msg"=>"出错了"]);
}
return json(["code"=>200,"msg"=>"网站地图获取成功"]);
}
骚嘿!每天30个开合跳,5分钟半支撑
当然也可以使用另一种方法生成 sitemap.xml