1、php生成sitemap.txt
$urls = [
'https://upwqy.com/'
];
$content = implode("\n", $urls);
$localUrl = './public/sitemap.txt';
$path = dirname($outfile);
!is_dir($path) && mkdir($path, 0755, true);
$f = fopen($outfile, 'w');
fwrite($f, $content);
fclose($f);
2、php生成sitemap.xml
// 生成sitemap.xml
$sitemapXmlTpl = <<<'eof'
<?xml version="1.0" encoding="utf-8"?>
<urlset>
%s
</urlset>
eof;
$xmlTpl = <<<'eof'
<url>
<loc>%s</loc>
<priority>0.8</priority>
</url>
eof;
$xml = '';
foreach ($urls as $url) {
$xml .= "\n".sprintf($xmlTpl, $url);
}
$content = sprintf($sitemapXmlTpl, $xml);
$localUrl = './public/sitemap.xml';
save_content_to_file($content, $localUrl);
发布时间 : 2023-02-28,阅读量:1220