Home >php教程 >php手册 >PHP制作google sitemaps PHP文章基地

PHP制作google sitemaps PHP文章基地

WBOY
WBOYOriginal
2016-06-21 09:05:58968browse

google|sitemap

把下面的代码作为一个php文件,传到网站根目录,运行一次,得到的根目录下的urls.txt即可以作为你网站的sitemaps提交给google!

注意:把代码里的网址改为你的首页

 


/***********************************************************************/
/*                                                                     */
/*  Author:CnPhper                                                     */
/*  HomePage: www.cnphper.com                                          */
/*  Email: phforum@163.com                                             */
/*  QQ:1984412                                                         */
/*                                                                     */
/***********************************************************************/

set_time_limit(0
);

$dir "./"
;
$yoursite ''yoursite
"; //此处把地址改为你的网站首页

get_dir($dir);

function get_dir($dir)
{
 if (is_dir($dir))
 {
  if ($dh = opendir($dir)) 
  {
   while (($file = readdir($dh)) !== false)
   {
    if($file != '.' && $file != '..')
    {
     if(is_dir($dir."
/
".$file))
     {
      if($dir == './')
      {
       $curdir = "
./
".substr($dir,2).$file;
      }
      else
      {
       $curdir = "
./".substr($dir,2)."/
".$file;
      }
      get_dir($curdir);
     }
     else
     {
      $currentdir = substr($dir,1);
      if($currentdir == '/')
      {
       $currentdir = "";
      }
      $fileextension = get_extension($file);
      $fp = fopen('urls.txt','a+');
      $txt = $yoursite.$currentdir."
/".$file." lastmod=2005-10-19 changefreq=weekly priority=0.5n
";
      fwrite($fp,$txt);
      fclose($fp);
     }
    }
   }
   closedir($dh);
  }
 }
}

function get_extension($file)
{
 $temp = explode('.',$file);
 $exten = count($temp)-1;
 return $temp[$exten];
}



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn