码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2014-11-18 23:02:36      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   os   div   on   log   cti   bs   

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

  

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

标签:blog   http   io   os   div   on   log   cti   bs   

原文地址:http://www.cnblogs.com/rnckty/p/4106259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!