火端搜索v2.1自行二开加入xml伪静态

 火端搜索v2.1自行二开加入xml伪静态,根据词库包生成xml,说干就干

首先在index.PHP文件中找到:

  

else if(preg_match("/sitemap\/(.+?).html/", $rewrite, $match)){
		$_GET['name']=$match[1];
		include('inc/sitemap.PHP');
	    exit;
	}

  在下面再添加以下代码

else if(preg_match("/sitemap\/(.+?).xml/", $rewrite, $match)){
		$type=='.xml';
		$_GET['name']=$match[1];
		include('inc/sitemapxml.PHP');
	    exit;
	}

  然后在/inc/下目录新建sitemapxml.PHP文件,如:

  

<?PHP
if(isset($_GET['name'])){
	$key = $_GET['name']; 
	$type='.xml';
	$dirname = ROOT_PATH.'/data/sitemap/';
	$file = $dirname.$key.'.txt';
	if(!is_file($file)){
		$file = $dirname.iconv("utf-8","gb2312",urldecode($key)).'.txt';
	}
	if($type=='.xml'){

		header("Content-type: text/xml"); 
		echo '<?xml version="1.0" encoding="utf-8"?>';
        echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
		
		 if(is_file($file)){
			 $worddata = file_get_contents($file);
			 if(strpos($worddata,"\r\n")>-1){
			    $words = explode("\r\n",$worddata);
			 }else{
				  $words = explode("\n",$worddata);
			 }
			
			  foreach($words as $k=>$v){
                if(strlen($v)>1){
				   echo '<url><loc>'.huoduansourl($v).'</loc></url>'."\r\n";
				}
			 }
		 }else{
			 echo 'Sitemap相关文件不存在';
		 }
		
		echo '</urlset>';
	}else{
		if(is_file($file)){
			 $worddata = file_get_contents($file);
			 if(strpos($worddata,"\r\n")>-1){
			    $words = explode("\r\n",$worddata);
			 }else{
				  $words = explode("\n",$worddata);
			 }
			
			  foreach($words as $k=>$v){
                 if(strlen($v)>1){
				    echo huoduansourl($v)."\r\n";
				 }
			 }
		 }else{
			 echo 'Sitemap相关文件不存在';
		 }
	}
	exit;
}
if(isset($_GET['name'])){
	$name = htmlspecialchars($_GET['name']); 
	if(substr($name,0,1)=='.' ||  substr($name,0,1)=='/'){
		echo 'Name参数不合法';exit;
	}
	$nametitle = $name.'相关词';
}
if(isset($_GET['p'])){
	$p=htmlspecialchars($_GET['p']);
}else{
	$p=1;
}
?>

  这样就完美了,演示地图:http://www.myjiancai.net/so/sitemap/fangzhukou.html 而他的地图版本是:http://www.myjiancai.net/so/sitemap/fangzhukou.xml

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念