-
数组要求
二位数组: 0: 网址, 1: 权重(0 ~ 1, 1 权重最大) $arr = array( [ 'https:'//www.sitemap.com', 1 ], [ 'https:'//www.sitemap.com/sitemap', 0.8 ], [ 'https:'//www.sitemap.com/sitemap/sitemap', 0.64 ], );
-
生成函数
/** * 生成XML */ function getXmlText($arr){ $xml=new SimpleXMLElement('<?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"/>'); foreach ($arr as $k) { $item=$xml->addchild("url"); $item->addchild("loc",$k[0]); $item->addchild("lastmod",date('c',time())); $item->addchild("priority",$k[1]); } header("Content-type: text/xml"); $xml->asXml("sitemap.xml"); }
网站站点地图SiteMap生成程序(PHP)
最新推荐文章于 2024-04-29 19:57:51 发布