php 生成符合google 地图标准xml类sitemap代码
<?php mysql_connect("localhost", "root", "root") or die('Database Server Uid or Password Error!'); mysql_select_db('ip') or die('data !'); mysql_query("SET NAMES 'gb2312'"); * /include ("boke/inc/re_conn.php"); $file = 'update.xml'; $url = '<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">'; $sql = "Select * from filecontent order by id desc limit 0,100 "; $query = mysql_query($sql); while ($rs = mysql_fetch_array($query)) { $time = filemtime(substr($rs['s_url'], 1)); $s = date("Y-m-d", $time); $s1 = date("H:i:s+00:00", $time); $s = $s . 'T' . $s1; $url.= "<url> <loc>http://www.phprm.com" . $rs['s_url'] . "</loc> <priority>1.00</priority> <lastmod>$s</lastmod> <changefreq>hourly</changefreq> </url> "; } if ($url) { $url.= "</urlset>"; null_write($url); echo '生成网站地图成功<a href=' . $file . ' target=_blank>查看</a>'; } function null_write($new) { global $file; $f = fopen($file, "w"); flock($f, LOCK_EX); fputs($f, $new); fclose($f); }
本文地址:http://www.phprm.com/code/4c9316419d699574f8b4285c88f07c7a.html
转载随意,但请附上文章地址:-)