php生成百度、神马、360、搜狗sitemap xml文件
作者:互联网
//yisvip_com_ecms_news 数据库名 网站名 目录名
private $footSite1 = ['wyhaa', 'aaaa'];
//www_haojio_com_ecms_news 数据库名 网站名 目录名
private $footSite2 = ['aaaa','bbbbb'];
public function generateXml(){
$footSite1 = $this->footSite1;
$footSite2 = $this->footSite2;
$this->generateGameUrlForXml999('yisvip_com_ecms_news',$footSite1);
$this->generateGameUrlForXml999('www_haojio_com_ecms_news',$footSite2);
}
//生成网站xml xml格式
public function generateGameUrlForXml999($table,$siteArr)
{
//查询当天产生的新闻id
// $currentDate = date("Y-m-d");
// $gameData = M('yisvip_com_ecms_news', '', 'mysql://root:admin@47.252.80.107/zhuayoukong1#utf8')
// dump($gameData);die;
// echo M()->getLastSql();die;
// $siteArr = $this->footSite;
//推送游戏
for ($i = 0; $i < count($siteArr); $i++) {
//$gameData = M('yisvip_com_ecms_news')
//www_haojio_com_ecms_news
$gameData = M($table, '', 'mysql://everyone:@45.205.141.194/'.$siteArr[$i].'#utf8')
->limit(10000)
->order('id desc')
->field('id,truetime,titleurl')
->select();
$urls = [];
$filename = "D:\sitemap\\".$siteArr[$i].'\sitemap.xml';
// $filename = '/data/www/'.$siteArr[$i].'/sitemap.xml';
// echo $filename;die;
$myfile = fopen($filename, "w") or die("Unable to open file!".$filename);
$content = '';
$content .= '<?xml version="1.0" encoding="utf-8"?>';
$content .= '<urlset>';
foreach ($gameData as $value) {
$content .= '<url>';
$content .= '<loc>'.'http://www.' . $siteArr[$i] .'.com'. $value['titleurl'].'</loc>';
// $content .= '<lastmod>'. $value['truetime'] .'</lastmod>';
$content .= '<lastmod>2019-8-04</lastmod>';
$content .= '<changefreq>daily</changefreq>';
$content .= '<priority>0.8</priority>';
$content .="</url>";
}
$content .= '</urlset>';
fwrite($myfile, $content);
fclose($fh);
}
}
标签:xml,搜狗,www,siteArr,ecms,content,news,php,com 来源: https://blog.csdn.net/helloworld_dream/article/details/100022248