知识屋:更实用的电脑技术知识网站
所在位置:首页 > 编程技术 > PHP编程

PHP通过访客来路获取搜索关键词的方法

发布时间:2014-09-05 10:43:15作者:知识屋

[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; 
    } 
 

 
 
 
?> 
(免责声明:文章内容如涉及作品内容、版权和其它问题,请及时与我们联系,我们将在第一时间删除内容,文章内容仅供参考)
收藏
  • 人气文章
  • 最新文章
  • 下载排行榜
  • 热门排行榜