程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> PHP通過訪客來路獲取搜索關鍵詞的方法

PHP通過訪客來路獲取搜索關鍵詞的方法

編輯:關於PHP編程
    <?php
    
    class keyword{
    
    	public function getKeyword($referer){
    		if(strpos($referer,"http://www.baidu.com")> -1 ){
    			$keyword = $this->getbaidukeyword($referer);
    		}else if(strpos($referer,"http://www.google.com")> -1 ){
    			$keyword = $this->getgooglekeyword($referer);
    		}else if(strpos($referer,"http://www.soso.com")> -1 ){
    			$keyword = $this->getsosokeyword($referer);
    		}else if(strpos($referer,"http://www.sogou.com")> -1 ){
    			$keyword = $this->getsogoukeyword($referer);
    		}
    		
    		return $keyword;
    	}
    	
    	//由來路取得百度關鍵詞
    	private function getbaidukeyword($str){
    		$s = strpos($str,'wd=');
    		if($s>-1){
    			$str = substr($str,$s+3);
    			$e = strpos($str,'&');
    			if($e>-1){
    				$str = substr($str,0,$e);
    			}
    			$str = rawurldecode($str);
    		}
    		return $str;
    	}
    	//獲得谷歌關鍵詞
    	private function getgooglekeyword($str){
    		$s = strpos($str,'&q=');
    		if($s>-1){
    			$str = substr($str,$s+3);
    			$e = strpos($str,'&');
    			if($e>-1){
    				$str = substr($str,0,$e);
    			}
    			$str = rawurldecode($str);
    		}
    		return $str;
    	}
    	//獲得SOSO關鍵詞
    	private function getsosokeyword($str){
    		$s = strpos($str,'?w=');
    		if($s>-1){
    			$str = substr($str,$s+3);
    			$e = strpos($str,'&');
    			if($e>-1){
    				$str = substr($str,0,$e);
    			}
    			$str = rawurldecode($str);
    		}else{
    			$s = strpos($str,'&w=');
    			if($s>-1){
    				$str = substr($str,$s+3);
    				$e = strpos($str,'&');
    				if($e>-1){
    					$str = substr($str,0,$e);
    				}
    				$str = rawurldecode($str);
    			}
    		}
    		return $str;
    	}
    	//獲得sogou關鍵詞
    	private function getsogoukeyword($str){
    		$s = strpos($str,'query=');
    		if($s>-1){
    			$str = substr($str,$s+6);
    			$e = strpos($str,'&');
    			if($e>-1){
    				$str = substr($str,0,$e);
    			}
    			$str = rawurldecode($str);
    		}
    		return $str;
    	}
    
    }
    
    
    
    ?>
    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved