1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

GG SiteMaps 自动生成程序 [php]

本帖由 小叶2006-05-19 发布。版面名称:后端开发

  1. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    将下程序生成PHP文件放到网站根目录运行即可自动生成
    PHP:
    <?

    //================== XML文件格式 ==================//
    function sitemap($strxml) {
            global 
    $part;
            
    $xmlstr.="   <url>\n";
            
    $xmlstr.="      <loc>".$strxml."</loc>\n";
            
    $xmlstr.="      <lastmod>".date("Y-m-d")."</lastmod>\n";
            
    $xmlstr.="       <changefreq>weekly</changefreq>\n";
            
    //$xmlstr.="      <priority>".$part."</priority>\n";
            
    $xmlstr.="      <priority>0.6</priority>\n";
            
    $xmlstr.="   </url>\n";
            return 
    $xmlstr;
    }

    //================== 获取目录中文件信息 ==================//
    function fileinfo($dir_name) {
            global 
    $dir_len,$part,$fp,$url;
            
    $part+=0.3;
            
    $dir opendir($dir_name);
            while(
    $file_name readdir($dir)){
                    if ((
    $file_name != ".") && ($file_name != "..")) {
                            if(
    is_dir($dir_name.'/'.$file_name)){
                                    
    fileinfo($dir_name.'/'.$file_name);
                            }else{
                                    
    $pi=pathinfo($file_name);
                                    if(
    $pi["extension"]=="htm" || $pi["extension"]=="asp" || $pi["extension"]=="php"){
                                            @
    fwrite($fpsitemap($url.substr($dir_name.'/'.$file_name,$dir_len)));
                                    }
                            }
                    }
            }
    }

    $url='http://'.$_SERVER['SERVER_NAME'];
    $part=0.3;
    $dir_name dirname(realpath("./sitemap.php"));
    $dir_len=strlen($dir_name);
    if(
    file_exists("$dir_name/sitemap.xml")) unlink("$dir_name/sitemap.xml");
    @
    $fp fopen("sitemap.xml"'a');
    @
    flock($fp2);
    @
    fwrite($fp"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    @
    fwrite($fp"<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n");
    fileinfo($dir_name) ;
    @
    fwrite($fp"</urlset>\n");
    @
    fclose($fp);
    ?>
     
  2. goosun

    goosun New Member

    注册:
    2006-03-31
    帖子:
    172
    赞:
    2
    将下程序生成PHP文件放到网站根目录运行即可自动生成

    PHP 代码:
    <?

    //================== XML文件格式 ==================//
    function sitemap($strxml) {
    global $part;
    $xmlstr.=" <url>\n";
    $xmlstr.=" <loc>".$strxml."</loc>\n";
    $xmlstr.=" <lastmod>".date("Y-m-d")."</lastmod>\n";
    $xmlstr.=" <changefreq>weekly</changefreq>\n";
    //$xmlstr.=" <priority>".$part."</priority>\n";
    $xmlstr.=" <priority>0.6</priority>\n";
    $xmlstr.=" </url>\n";
    return $xmlstr;
    }

    //================== 获取目录中文件信息 ==================//
    function fileinfo($dir_name) {
    global $dir_len,$part,$fp,$url;
    $part+=0.3;
    $dir = opendir($dir_name);
    while($file_name = readdir($dir)){
    if (($file_name != ".") && ($file_name != "..")) {
    if(is_dir($dir_name.'/'.$file_name)){
    fileinfo($dir_name.'/'.$file_name);
    }else{
    $pi=pathinfo($file_name);
    if($pi["extension"]=="htm" || $pi["extension"]=="asp" || $pi["extension"]=="php"){
    @fwrite($fp, sitemap($url.substr($dir_name.'/'.$file_name,$dir_len)));
    }
    }
    }
    }
    }

    $url='http://'.$_SERVER['SERVER_NAME'];
    $part=0.3;
    $dir_name = dirname(realpath("./sitemap.php"));
    $dir_len=strlen($dir_name);
    if(file_exists("$dir_name/sitemap.xml")) unlink("$dir_name/sitemap.xml");
    @$fp = fopen("sitemap.xml", 'a');
    @flock($fp, 2);
    @fwrite($fp, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
    @fwrite($fp, "<urlset xmlns=\"http://www.google.com/schemas/sitemap/0.84\">\n");
    fileinfo($dir_name) ;
    @fwrite($fp, "</urlset>\n");
    @fclose($fp);
    ?>
     
  3. 极品蜗牛

    极品蜗牛 New Member

    注册:
    2005-10-20
    帖子:
    673
    赞:
    2
    好东西...谢谢