Rice flapping technology products, is currently doing SEO site optimization, One of the sub-requirements is the survey to achieve the site map (SITEMAP.XML)
The package simplifies many function modules and is now shared, and the source code can be downloaded on GitHub with a simple example.
Github Open Source URL : sitemap-php
What is sitemap-php?
Sitemap-php is a lightweight, simple and fast-generating site map of Open-source projects, by Beijing Mi Technology co., Ltd. (mimvp.com) Development and Sharing.
A simple configuration definition, a function Createsitemap (), can automatically generate sitemap.xml, sitemap.html and other Web site map files,
Automatically generated xml, HTML files, support google, Bing, Baidu and other mainstream search engine Included.
Fast and lightweight class for generating Google sitemap XML files and index of Sitemaps Files.
Written on PHP and uses XMLWriter extension (wrapper for libxml XMLWriter apis) for creating XML Files. XMLWriter extension is enabled by default in PHP 5 >= 5.1.2.
If you have more than 50000 urls, it splits items to seperated files. (in benchmarks, 1.000.000 URL is generating in 8 Seconds)
Example: Sitemap.xml:http://mimvp.com/sitemap.xmlsitemap.html:http://mimvp.com/sitemap.htmlhow to use
sitemap encapsulates the class that generates the properties and methods of sitemap.xml, using very simple, sample code:
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 ', ' June 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 ();}
Initializing class objects
$sitemap = new Sitemap ("http://mimvp.com");
Add Item
$sitemap->additem ('/', ' 1.0 ', ' daily ', ' today '), $sitemap->additem ('/hr.php ', ' 0.8 ', ' monthly ', time ()); $ Sitemap->additem ('/index.php ', ' 1.0 ', ' daily ', ' June '), $sitemap->additem ('/about.php ', ' 0.8 ', ' monthly ', ' 2017-06-26 ');
Or
$sitemap->additem ('/hr2.php ', ' 1.0 ', ' daily ', time ())->additem ('/index2.php ', ' 1.0 ', ' daily ', ' today ') AddItem ('/about2.php ', ' 0.8 ', ' monthly ', ' June 25 ');
End Document
$sitemap->endsitemap ();
-
Generate results sitemap.xml
<?xml version= "1.0" encoding= "UTF-8"? ><urlset 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 " xmlns=" http://www.sitemaps.org/schemas/sitemap/0.9 "> <url><loc>http://mimvp.com/</loc><priority>1.0</priority><changefreq>daily </changefreq><lastmod>2017-06-26T00:00:00+08:00</lastmod></url><url><loc> http://mimvp.com/hr.php</loc><priority>0.8</priority><changefreq>monthly</ changefreq><lastmod>2017-06-26t20:16:23+08:00</lastmod></url><url><loc>http:/ /mimvp.com/index.php</loc><priority>1.0</priority><changefreq>daily</changefreq> <lastmod>2017-06-25t00:00:00+08:00</lastmod></url><url><loc>http://mimvp.com/ About.php</loc><priority>0.8</priority><changefreq>monthly</changefreq><lastmod>2017-06-26t00:00:00+08:00</ Lastmod></url></urlset>
More Functions
Set the root domain name
$sitemap = new Sitemap ("http://mimvp.com");
You can also modify the initialized domain name to
$sitemap->setdomain (' http://blog.mimvp.com ');
Set save path Sitemap.xml by default in the current directory, you can also set the folder directory, for Example: xmls/sitemap, Sitemap.xml is saved in the current directory under the xmls/directory, where the xmls directory is automatically created. Note: Multi-level catalogs are supported
$sitemap->setxmlfile ("xmls/sitemap"); $sitemap->setxmlfile ("xmls/mimvp/sitemap");
Set whether more headers
$sitemap->setischemamore (true);
If set to true, some header information is added to the header of the Sitemap.xml file:
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 "
Gets the currently written sitemap file
$sitemap->getcurrxmlfilefullpath ();
Advanced Functions
Specify the Include file With/start
$GIncludeArray = array ("", "/index.php", "about.php", "hr.php");
Exclude specific files or directories
$GExcludeArray = array ("usercenter/", "sadmin/", "admin/", "sitemap.php");
Recursive scan of the specified directory, default scanning layer three (can be set by Itself)
function Scanrootpath ($rootPath = ".", $dirLevel =1, $MaxDirLevel =3, & $resArray =array ())
Convert XML + XSL to HTML
function createxsl2html ($xmlFile, $xslFile, $htmlFile, $isopen _htmlfile=false)
Sitemap Demo
Global variables, G start
$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);
Generate Sitemap.xml
Createsitemap ();
Build Example:
650) this.width=650; "src=" https://github.com/mimvp/sitemap-php/raw/master/mimvp-sitemap-xml.png "alt=" sitemap.xml example "style=" Border-style:none;background-color:rgb (255,255,255); "/>
Generate sitemap.html
createxsl2html ($xmlFile, $xslFile, $htmlFile, $isopen _htmlfile=false);
Build Example:
650) this.width=650; "src=" https://github.com/mimvp/sitemap-php/raw/master/mimvp-sitemap-html.png "alt=" sitemap.html example "style=" Border-style:none;background-color:rgb (255,255,255); "/>
You need to submit sitemap.xml and sitemap.html to Google, Bing, baidu,etc.
Sitemap-php project, currently support the designated Web pages, exclude pages, scan the root directory and other sites map;
When the latter is perfected, it will increase the ability to export the database, crawl the whole website, etc.
Also hope that you join, continue to improve this project
sitemap-php All rights by mimvp.com
This article is from the "rice flutter column" blog, Make sure to keep this source http://mimvp.blog.51cto.com/13185516/1954275
Open source Project: sitemap-php auto-generated Site Map