PHP to make Google sitemaps--php article base

Source: Internet
Author: User
Tags php file root directory
Google|sitemap

put the following code as a php file, upload the site root directory, run once, and get the URLs under the root directory.txt that can be used as your site's sitemaps submitted to google!

Note: Change the URL in the code to your home page




/***********************************************************************/
/*                                                                     */
* Author:cnphper * *
* HomePage:www.cnphper.com * *
* email:phforum@163.com * *
* qq:1984412 * *
/*                                                                     */
/***********************************************************************/

Set_time_limit (0);

$dir = "./";
$yoursite = ' Yoursite"; Here, change the address to your home page

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 = "./       }
      else
      {
         $curdir  =  "./". substr ($dir, 2). " /       }
      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];
}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.