php语言

php生成sitemap.xml的实例代码

时间:2025-04-13 17:42:21 php语言 我要投稿
  • 相关推荐

php生成sitemap.xml的实例代码

  本文分享一个自己写的生成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实用的代码实例08-12

学习php分页代码实例05-20

PHP生成SiteMap文件的代码03-05

php动态生成JavaScript代码03-12

实用的PHP实例代码20个06-11

实用的PHP语言实例代码06-13

PHP时间戳使用实例代码03-10

php自动生成sitemap地图的代码07-31

php自动生成sitemap地图代码05-23