php生成sitemap.xml

 
更多

本人写的一个利用php生成sitemap.xml文件,对网站的SEO非常有帮助的,在此分享一下。

<?PHP
$content='<?xml version="1.0" encoding="UTF-8"?>
<urlset
    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9
       http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
';
$data_array=array(
    array(
		'loc'=>'http://www.phpernote.com/',
		'priority'=>'1.0',
		'lastmod'=>'2012-06-03T04:20:32-08:00',
		'changefreq'=>'always'
    ),
    array(
		'loc'=>'http://www.phpernote.com/php/',
		'priority'=>'0.5',
		'lastmod'=>'2012-06-03T04:20:32-08:00',
		'changefreq'=>'daily'
    )
);
foreach($data_array as $data){
	$content.=create_item($data);
}
$content.='</urlset>';
$fp=fopen('sitemap.xml','w+');
fwrite($fp,$content);
fclose($fp);

function create_item($data){
    $item="<url>\n";
    $item.="<loc>".$data['loc']."</loc>\n";
    $item.="<priority>".$data['priority']."</priority>\n";
    $item.="<lastmod>".$data['lastmod']."</lastmod>\n";
	$item.="<changefreq>".$data['changefreq']."</changefreq>\n";
    $item.="</url>\n";
    return $item;
}

Sitemap.xml 制作完成后,就需要将xml文件提交到相关搜索引擎以方便搜索引擎更快速的收录了,下面列举几个比较常见的搜索引擎的sitemap的提交地址。
 
Google 提交地址:http://www.google.com/webmasters/sitemaps/?hl=zh-CN
 
Yahoo 提交地址:http://sitemap.cn.yahoo.com/
 
提交后,一般在几个小时之内,系统就开始下载处理了。

关于sitemap.xml的具体作用请参考:http://baike.baidu.com/view/1072062.htm(百度百科:sitemap.xml)

打赏

本文固定链接: https://www.cxy163.net/archives/3685 | 绝缘体-小明哥的技术博客

该日志由 绝缘体.. 于 2015年04月27日 发表在 go, PHP, 百度, 科技企业, 编程语言 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: php生成sitemap.xml | 绝缘体-小明哥的技术博客
关键字: , , , ,

php生成sitemap.xml:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter