1. 程式人生 > 其它 >火端搜尋v2.1自行二開加入xml偽靜態

火端搜尋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

千行程式碼,Bug何處藏。 縱使上線又怎樣,朝令改,夕斷腸。