如果有个库,可以使用同样的信息,来程序化同时创建Yahoo!和Google站点地图,将是很有用的。这个练习将会演示这样一个库。
首先创建类sitemap,用于存储站点中的一系列链接,再生成相应的确Yahoo!和Google站点地图文件。
生成站点地图
(一)在seophp/include文件夹,创建新文件sitemap.inc.php,键入如下代码:
<?php
class sitemap
{
function sitemap($itema=array())
{
$this->_items=$items;
}
function addItem($url,$lastmod='',$changefreg='',$priority='',$additional_fields=array())
{
$this->_items[]=array_merge(array('loc'=>$url,'lastmod'=>$lastmod,'changefreq'=>$changefreq,'priority'=>$priority),$additional_fields);
}
function getGoogle(){
ob_start();
header('Content-type:text/xml');
echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<urlset xmlns=http://www.google.com/schemas/sitemap/0.84>';
foreach($this->_items as $i)
echo '<url>';
foreach($i as $index=>$_i)
{
if(!$_i) continue;
echo "<$index>".$this->_escapeXML($_i)."</index>";
}
echo '</url>';
}
echo '</urlset>';
return ob_get_clean();
}
function getYahoo()
{
ob_start();
header('Content-type:text/plain');
foreach($this->_items as $i)
{
echo $i['loc']."n";
}
return ob_get_clean();
}
function _escapeXML($str)
{
$translation=gt_html_translation_table(HTML_ENTITIES,ENT_QUOTES);
foreach($translation as $key=>$value)
{
$translation[$key]='&#'.ord($key).";";
}
$tramslation[chr(38)]='&';
return
preg_replace("/&(?![A-za-z]{0.4}w{2,3};)/","&",strtr($str,$translation));
}
?>
希望以上的这些信息能够帮助您,如果您还有关于大连网站制作,大连网站建设及企业邮箱等相关问题,请与我们联系,新图闻科技将竭诚为您服务!