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:[email protected]/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://username:@41.225.111.192/'.$siteArr[$i].'#utf8')  //ip是错的 改成自己的
            ->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 .= '';
             $content .= '';
                  foreach ($gameData as $value) {
                      $content .= '';
                      $content .= ''.'http://www.' . $siteArr[$i] .'.com'. $value['titleurl'].'';
                     // $content .= ''. $value['truetime'] .'';
                      $content .= '2019-8-04';
                      $content .= 'daily';
                      $content .= '0.8';
                      $content .="";
                  }
            $content .= '';
            fwrite($myfile, $content);
            fclose($fh);
        }

        


    }

 

 

 

你可能感兴趣的:(php)