将下程序生成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); ?>
将下程序生成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); ?>