当前位置:首页> PHP教程> PHP代码
关键字
文章内容
PHP制作google sitemaps
 
 
修改时间:[2010/06/09 12:17]    阅读次数:[607]    发表者:[起缘]
 

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

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

 

/***********************************************************************/
/*                                                                     */
/*  Author:                                                     */
/*  HomePage: www.cnphper.com                                          */
/*  Email:                                              */
/*  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.5\n";
      fwrite($fp,$txt);
      fclose($fp);
     }
    }
   }
   closedir($dh);
  }
 }
}

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

?>