微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

mimvp-sitemap-php What is sitemap-php ?示例:How to useMore FunctionsAdvanced FunctionsSitemap Demo 轻量级、轻量级简单快速生成网站地图

程序名称:mimvp-sitemap-php What is sitemap-php ?示例:How to useMore FunctionsAdvanced FunctionsSitemap Demo

授权协议: MIT

操作系统: 跨平台

开发语言: PHP

mimvp-sitemap-php What is sitemap-php ?示例:How to useMore FunctionsAdvanced FunctionsSitemap Demo 介绍

What is sitemap-PHP ?

sitemap-PHP
一个轻量级、简单快速生成网站地图的开源项目,由北京米扑科技有限公司(mimvp.com)开发分享

通过简单的配置定义,一个函数createSitemap(),可自动生成sitemap.xml、sitemap.html等网站地图文件,

自动生成的xml、html文件支持Google、Bing、Baidu等主流搜索引擎收录。

Fast and lightweight class for generating Google sitemap XML files and index
of sitemap files.

Written on PHP and uses XMLWriter extension (wrapper for libxml xmlWriter API)
for creating XML files. XMLWriter extension is enabled by default in PHP 5 >=
5.1.2.

If you having more than 50000 url, it splits items to seperated files. (In
benchmarks, 1.000.000 url was generating in 8 seconds)

示例:

sitemap.xml : http://mimvp.com/sitemap.xml

sitemap.html : http://mimvp.com/sitemap.html

How to use

Sitemap 封装了生成sitemap.xml的属性方法的类,使用非常简单,示例代码

function testSitemap() {
    $sitemap = new Sitemap("http://mimvp.com");

     $sitemap->addItem('/', '1.0', 'daily', 'Today');
     $sitemap->addItem('/hr.PHP', '0.8', 'monthly', time());
     $sitemap->addItem('/index.PHP', '1.0', 'daily', 'Jun 25');
     $sitemap->addItem('/about.PHP', '0.8', 'monthly', '2017-06-26');
     
     $sitemap->addItem('/hr2.PHP', '1.0', 'daily', time())->addItem('/index2.PHP', '1.0', 'daily', 'Today')->addItem('/about2.PHP', '0.8', 'monthly', 'Jun 25');
     
     $sitemap->endSitemap();
}
  • 初始化类对象

    $sitemap = new Sitemap("http://mimvp.com”);

  • 添加Item

    $sitemap->addItem(‘/’, ‘1.0’, ‘daily’, ‘Today’);
    $sitemap->addItem(‘/hr.PHP’, ‘0.8’, ‘monthly’, time());
    $sitemap->addItem(‘/index.PHP’, ‘1.0’, ‘daily’, ‘Jun 25’);
    $sitemap->addItem(‘/about.PHP’, ‘0.8’, ‘monthly’, ‘2017-06-26’);

或者

$sitemap->addItem('/hr2.PHP', '1.0', 'daily', time())->addItem('/index2.PHP', '1.0', 'daily', 'Today')->addItem('/about2.PHP', '0.8', 'monthly', 'Jun 25');

More Functions

也可以修改初始化的域名为

$sitemap->setDomain('http://blog.mimvp.com');
  • 设置保存路径 sitemap.xml认保存在当前目录下,也可设置文件夹目录,例如: xmls/sitemap,表示sitemap.xml保存在当前目录下的xmls/目录下,其中xmls目录会自动创建。注:支持多级目录

    $sitemap->setXmlFile(“xmls/sitemap”);
    $sitemap->setXmlFile(“xmls/mimvp/sitemap”);

  • 设置是否更多头部

    $sitemap->setIsChemaMore(true);

如果设置为true,则sitemap.xml文件头部会增加一些头部信息

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"
  • 获取当前写入的sitemap文件

    $sitemap->getCurrXmlFileFullPath();

Advanced Functions

  1. 指定包含文件,以/开头

    $GIncludeArray = array(“”, ”/index.PHP”, “about.PHP”, “hr.PHP”);

  2. 排除特定文件或目录

    $GExcludeArray = array(“usercenter/”, “sadmin/”, “admin/”, “sitemap.PHP”);

  3. 递归扫描指定目录,认扫描三层(可自己设定)

    function scanRootPath($rootPath=”.”, $dirLevel=1, $MaxDirLevel=3, &$resArray=array())

  4. 转化 xml + xsl 为 html

    function createXSL2Html($xmlFile, $xslFile, $htmlFile, $isopen_htmlfile=false)

Sitemap Demo

  1. 全局变量,G开头

    $GCONfig = array( "domain"=>"http://mimvp.com”,
    “xmlfile”=>”sitemap”,
    “htmlfile”=>”sitemap.html”,
    “xslfile”=>”sitemap-xml.xsl”,
    “isopen_xmlfile”=>true,
    “isopen_htmlfile”=>true,
    “isscanrootpath”=>true,
    “isxsl2html”=>true,
    “isschemamore”=>true);

  2. 生成sitemap.xml

    createSitemap();

生成示例:

  1. 生成 sitemap.html

    createXSL2Html($xmlFile, $xslFile, $htmlFile, $isopen_htmlfile=false);

生成示例:

You need to submit sitemap.xml and sitemap.html to Google、 Bing、 Baidu,etc.

sitemap-PHP项目,目前支持指定网页、排除网页、扫描根目录等网站地图
后期完善时,会增加导出数据库、爬取整个网站等功能
也希望您的加入,继续完善此项目

sitemap-PHP All Rights by mimvp.com

mimvp-sitemap-php What is sitemap-php ?示例:How to useMore FunctionsAdvanced FunctionsSitemap Demo 官网

https://github.com/mimvp/sitemap-php

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐