生产Google Sitemap XML文件的PHP代码

本文介绍如何通过PHP代码创建Google Sitemap XML文件。只需将代码保存并上传至服务器,运行后即可在指定目录生成sitemap.xml。完成后,登录Google Webmaster Tools提交XML文件地址,确保搜索引擎能及时抓取网站新增内容。
摘要由CSDN通过智能技术生成
php如何生成Google Sitemap XML文件:
<?php 
header('Content-type: application/xml; charset="GB2312"',true); 
$timezone    = "Asia/Shanghai";
date_default_timezone_set($timezone);

$website = "http://www.yipiantian.cn"; /* change this */ 
$page_root = "/usr/local/psa/home/vhosts/subdomains/my/httpdocs"; /* change this */ 


/* maybe change this: */ 
$changefreq = "daily"; //"always", "hourly", "daily", "weekly", "monthly", "yearly" and "never". 
$priority = 0.5; 
/* this sets the last modification date of all pages to the current date */ 
$last_modification = date("Y-m-d H:i:s"); 

/* list of allowed directories */ 
$allow_dir[] = "about"; 
$allow_dir[] = "help"; 
$allow_dir[] = "case"; 
$allow_dir[] = "E-Marketing"; 

/* list of disallowed directories */ 
$disallow_dir[] = "system"; 
$disallow_dir[] = "ads"; 
$disallow_dir[] = "api"; 
$disallow_dir[] = "ask"; 
$disallow_dir[] = "category"; 
$disallow_dir[] = "comment"; 
$disallow_dir[] = "corpandresize"; 
$disallow_dir[] = "css"; 

/* list of disallowed file types */ 
$disallow_file[] = ".inc"; 
$disallow_file[] = ".old"; 
$disallow_file[] = ".save"; 
$disallow_file[] = ".txt"; 
$disallow_file[] = ".xml"; 
$disallow_file[] = ".js"; 
$disallow_file[] = "~"; 
$disallow_file[] = ".LCK"; 
$disallow_file[] = ".zip"; 
$disallow_file[] = ".ZIP"; 
$disallow_file[] = ".CSV"; 
$disallow_file[] = ".csv"; 
$disallow_file[] = ".css"; 
$disallow_file[] = ".class"; 
$disallow_file[] = ".jar"; 
$disallow_file[] = ".mno"; 
$disallow_file[] = ".bak"; 
$disallow_file[] = ".lck"; 
$disallow_file[] = ".BAK"; 
$disallow_file[] = ".php"; 
$disallow_file[] = ".sql"; 

/* simple compare function: equals */ 
function ar_contains($key, $array) { 
foreach ($array as $val) { 
if ($key == $val) { 
return true; 
} 
} 
return false; 
} 

/* better compare function: contains */ 
function fl_contains($key, $array) { 
foreach ($array as $val) { 
$pos = strpos($key, $val); 
if ($pos === FALSE) continue; 
return true; 
} 

return false; 
} 

/* this function changes a substring($old_offset) of each array element to $offset */ 
function changeOffset($array, $old_offset, $offset) { 
$res = array(); 
foreach ($array as $val) { 
$res[] = str_replace($old_offset, $offset, $val); 
} 
return $res; 
} 

/* this walks recursivly through
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值