有关GOOGLE SITEMAP的文章请看: http://andsky.com/show.php?id=436
PHP版 :
参数说明:
$website--你的域名
$page_root--你的站点的绝对路径
$changefreq--更新时间单位 "always"(始终), "hourly"(小时), "daily"(天), "weekly"(星期), "monthly"(月), "yearly" "never"(从不)
$priority--更新频率
$allow_dir--允许列表的目录
$disallow_dir--禁止列表的目录
$disallow_file--禁止列表的文件类型
1
2header('Content-type: application/xml; charset="GB2312"',true);
1
2$website = " http://my.xxxxx.com "; /* change this */
3$page_root = "/usr/local/psa/home/vhosts/subdomains/my/httpdocs"; /* change this */
4
5/* maybe change this: */
6$changefreq = "weekly"; //"always", "hourly", "daily", "weekly", "monthly", "yearly" and "never".
7$priority = 0.8;
8/* this sets the last modification date of all pages to the current date */
9$last_modification = date("Y-m-d\TH:i:s") . substr(date("O"),0,3) . ":" . substr(date("O"),3);
10
11/* list of allowed directories */
12$allow_dir[] = "web";
13
14/* list of disallowed directories */
15$disallow_dir[] = "admin";
16$disallow_dir[] = "_notes";
17
18/* list of disallowed file types */
19$disallow_file[] = ".inc";
20$disallow_file[] = ".old";
21$disallow_file[] = ".save";
22$disallow_file[] = ".txt";
23$disallow_file[] = ".js";
24$disallow_file[] = "~";
25$disallow_file[] = ".LCK";
26$disallow_file[] = ".zip";
27$disallow_file[] = ".ZIP";
28$disallow_file[] = ".CSV";
29$disallow_file[] = ".csv";
30$disallow_file[] = ".css";
31$disallow_file[] = ".class";
32$disallow_file[] = ".jar";
33$disallow_file[] = ".mno";
34$disallow_file[] = ".bak";
35$disallow_file[] = ".lck";
36$disallow_file[] = ".BAK";
37
38/* simple compare function: equals */
39function ar_contains( $key, $array) {
40foreach ( $array as $val) {
41if ( $key == $val) {
42return true;
43}
44}
45return false;
46}
47
48/* better compare function: contains */
49function fl_contains( $key, $array) {
50foreach ( $array as $val) {
51$pos = strpos( $key, $val);
52if ( $pos === FALSE) continue;
53return true;
54}
55
56return false;
57}
58
59/* this function changes a substring( $old_offset) of each array element to $offset */
60function changeOffset( $array, $old_offset, $offset) {
61$res = array();
62foreach ( $array as $val) {
63$res[] = str_replace( $old_offset, $offset, $val);
64}
65return $res;
66}
67
68/* this walks recursivly through all directories starting at page_root and
69adds all files that fits the filter criterias */
70// taken from Lasse Dalegaard, http://php.net/opendir
71function getFiles( $directory, $directory_orig = "", $directory_offset="") {
72global $disallow_dir, $disallow_file, $allow_dir;
73
74if ( $directory_orig == "") $directory_orig = $directory;
75
76if( $dir = opendir( $directory)) {
77// Create an array for all files found
78$tmp = Array();
79
80// Add the files
81while( $file = readdir( $dir)) {
82// Make sure the file exists
83if( $file != "." && $file != ".." && $file[0] != '.' ) {
84// If it's a directiry, list all files within it
85//echo "point1
<br/>
1";
2if(is_dir( $directory . "/" . $file)) {
3//echo "point2
<br/>
1";
2$disallowed_abs = fl_contains( $directory."/". $file, $disallow_dir); // handle directories with pathes
3$disallowed = ar_contains( $file, $disallow_dir); // handle directories only without pathes
4$allowed_abs = fl_contains( $directory."/". $file, $allow_dir);
5$allowed = ar_contains( $file, $allow_dir);
6if ( $disallowed || $disallowed_abs) continue;
7if ( $allowed_abs || $allowed){
8$tmp2 = changeOffset(getFiles( $directory . "/" . $file, $directory_orig, $directory_offset), $directory_orig, $directory_offset);
9if(is_array( $tmp2)) {
10$tmp = array_merge( $tmp, $tmp2);
11}
12}
13} else { // files
14if (fl_contains( $file, $disallow_file)) continue;
15array_push( $tmp, str_replace( $directory_orig, $directory_offset, $directory."/". $file));
16}
17}
18}
19
20// Finish off the function
21closedir( $dir);
22return $tmp;
23}
24}
25
26$a = getFiles( $page_root);
27
28
29echo '
30<?xml version="1.0" encoding="UTF-8"
31```';
32?>