Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php生成sitemap.xml的实例代码

php生成sitemap.xml的实例代码

发布时间:2017-04-10   编辑:www.jquerycn.cn
本文分享一个自己写的生成sitemap.xml文件的php代码,感兴趣的朋友可以参考下。

本节内容:
php生成sitemap.xml

例子:
 

复制代码 代码示例:

<?PHP
/**
* 生成sitemap.xml文件
*/
$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.jbxue.com/',
  'priority'=>'1.0',
  'lastmod'=>'2012-06-03T04:20:32-08:00',
  'changefreq'=>'always'
    ),
    array(
  'loc'=>'http://www.jbxue.com/',
  '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

您可能感兴趣的文章:
php生成sitemap.xml的实例代码
php自动生成sitemap地图的代码
php生成sitemap.xml的简单代码
Google Sitemap更快更全面收录网站
PHP生成sitemap.xml的代码浅析
详解Django中的sitemap
php生成随机产生六位数密码的代码
php生成word最简单的例子
PHP每15分钟自动更新网站地图(减少服务器消耗)
PHP生成SiteMap文件的代码

[关闭]