Whatissitemap-php?
sitemap-php是一个轻量级、简单快速生成网站地图的开源项目,由北京米扑科技有限公司(mimvp.com)开发分享。
通过简单的配置定义,一个函数createSitemap(),可自动生成sitemap.xml、sitemap.html等网站地图文件,
自动生成的xml、html文件,支持Google、Big、Baidu等主流搜索引擎收录。
FastadlightweightclassforgeeratigGooglesitemapXMLfilesadidexofsitemapfiles.
WritteoPHPadusesXMLWriterextesio(wrapperforlibxmlxmlWriterAPI)forcreatigXMLfiles.XMLWriterextesioiseabledbydefaultiPHP5>=5.1.2.
Ifyouhavigmoretha50000url,itsplitsitemstoseperatedfiles. (Ibechmarks,1.000.000urlwasgeeratigi8secods)
示例:sitemap.xml: https://mimvp.com/sitemap.xml
sitemap.html: https://mimvp.com/sitemap.html
HowtouseSitemap封装了生成sitemap.xml的属性和方法的类,使用非常简单,示例代码:
fuctio testSitemap() {$sitemap = ew Sitemap("https://mimvp.com"); $sitemap->addItem('/', '1.0', 'daily', 'Today'); $sitemap->addItem('/hr.php', '0.8', 'mothly', time()); $sitemap->addItem('/idex.php', '1.0', 'daily', 'Ju 25'); $sitemap->addItem('/about.php', '0.8', 'mothly', '2017-06-26'); $sitemap->addItem('/hr2.php', '1.0', 'daily', time())->addItem('/idex2.php', '1.0', 'daily', 'Today')->addItem('/about2.php', '0.8', 'mothly', 'Ju 25'); $sitemap->edSitemap();}初始化类对象
$sitemap = ew Sitemap("https://mimvp.com");添加Item
$sitemap->addItem('/', '1.0', 'daily', 'Today');$sitemap->addItem('/hr.php', '0.8', 'mothly', time());$sitemap->addItem('/idex.php', '1.0', 'daily', 'Ju 25');$sitemap->addItem('/about.php', '0.8', 'mothly', '2017-06-26');或者
$sitemap->addItem('/hr2.php', '1.0', 'daily', time())->addItem('/idex2.php', '1.0', 'daily', 'Today')->addItem('/about2.php', '0.8', 'mothly', 'Ju 25');结束文档
$sitemap->edSitemap();生成结果sitemap.xml
<?xml versio="1.0" ecodig="UTF-8"?><urlset xmls:xsi="https://www.w3.org/2001/XMLSchema-istace" xsi:schemaLocatio="https://www.sitemaps.org/schemas/sitemap/0.9 https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmls="https://www.sitemaps.org/schemas/sitemap/0.9"><url><loc>https://mimvp.com/</loc><priority>1.0</priority><chagefreq>daily</chagefreq><lastmod>2017-06-26T00:00:00+08:00</lastmod></url><url><loc>https://mimvp.com/hr.php</loc><priority>0.8</priority><chagefreq>mothly</chagefreq><lastmod>2017-06-26T20:16:23+08:00</lastmod></url><url><loc>https://mimvp.com/idex.php</loc><priority>1.0</priority><chagefreq>daily</chagefreq><lastmod>2017-06-25T00:00:00+08:00</lastmod></url><url><loc>https://mimvp.com/about.php</loc><priority>0.8</priority><chagefreq>mothly</chagefreq><lastmod>2017-06-26T00:00:00+08:00</lastmod></url></urlset>MoreFuctios设置根域名
$sitemap = ew Sitemap("https://mimvp.com");也可以修改初始化的域名为
$sitemap->setDomai('https://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文件头部会增加一些头部信息:
xmls:xsi="https://www.w3.org/2001/XMLSchema-istace" xsi:schemaLocatio="https://www.sitemaps.org/schemas/sitemap/0.9 https://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"获取当前写入的sitemap文件
$sitemap->getCurrXmlFileFullPath();AdvacedFuctios指定包含文件,以/开头
$GIcludeArray = array("", "/idex.php", "about.php", "hr.php");排除特定文件或目录
$GExcludeArray = array("userceter/", "sadmi/", "admi/", "sitemap.php");递归扫描指定目录,默认扫描三层(可自己设定)
fuctio scaRootPath($rootPath=".", $dirLevel=1, $MaxDirLevel=3, &$resArray=array())转化xml+xsl为html
fuctio createXSL2Html($xmlFile, $xslFile, $htmlFile, $isope_htmlfile=false)SitemapDemo全局变量,G开头
$GCONFIG = array("domai"=>"https://mimvp.com","xmlfile"=>"sitemap","htmlfile"=>"sitemap.html","xslfile"=>"sitemap-xml.xsl","isope_xmlfile"=>true,"isope_htmlfile"=>true,"isscarootpath"=>true,"isxsl2html"=>true,"isschemamore"=>true);生成sitemap.xml
createSitemap();生成示例:
生成sitemap.html
createXSL2Html($xmlFile, $xslFile, $htmlFile, $isope_htmlfile=false);生成示例:
Youeedtosubmitsitemap.xmladsitemap.htmltoGoogle、Big、Baidu,etc.
sitemap-php项目,目前支持指定网页、排除网页、扫描根目录等网站地图;后期完善时,会增加导出数据库、爬取整个网站等功能,也希望您的加入,继续完善此项目
sitemap-php All Rights by mimvp.com
评论