Home  >  Article  >  php教程  >  php获取网站关键词

php获取网站关键词

PHP中文网
PHP中文网Original
2016-05-25 17:09:481059browse

1. [代码]php代码              

<?php 
$_SERVER[&#39;HTTP_REFERER&#39;]=&#39;http://www.baidu.com/s?wd=http://www.php.cn/&#39;; 
echo save_www_iiwnet_com_keyword(&#39;http://www.baidu.com/s?wd=http://www.php.cn/&#39;,&#39;http://www.baidu.com/s?wd=http://www.php.cn/&#39;); 
function save_www_iiwnet_com_keyword($domain,$path){ 
 if(strpos($domain, &#39;google.com.tw&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
  $searchengine = &#39;GOOGLE TAIWAN&#39;; 
  $keywords = urldecode($regs[1]); // google taiwan 
    } 
 if(strpos($domain,&#39;google.cn&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
  $searchengine = &#39;GOOGLE CHINA&#39;; 
  $keywords = urldecode($regs[1]); // google china 
 } 
 if(strpos($domain,&#39;google.com&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
  $searchengine = &#39;GOOGLE&#39;; 
  $keywords = urldecode($regs[1]); // google 
 }elseif(strpos($domain,&#39;baidu.&#39;)!==false && preg_match(&#39;/wd=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;BAIDU&#39;; 
        $keywords = urldecode($regs[1]); // baidu 
    }elseif(strpos($domain,&#39;baidu.&#39;)!==false && preg_match(&#39;/word=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;BAIDU&#39;; 
        $keywords = urldecode($regs[1]); // baidu 
    }elseif(strpos($domain,&#39;114.vnet.cn&#39;)!== false && preg_match(&#39;/kw=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;CT114&#39;; 
        $keywords = urldecode($regs[1]); // ct114 
    }elseif(strpos($domain,&#39;iask.com&#39;)!==false && preg_match(&#39;/k=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;IASK&#39;; 
        $keywords = urldecode($regs[1]); // iask 
    }elseif(strpos($domain,&#39;soso.com&#39;)!==false && preg_match(&#39;/w=([^&]*)/i&#39;,$path,$regs)){ 
  $searchengine = &#39;SOSO&#39;; 
        $keywords = urldecode($regs[1]); // soso 
    }elseif(strpos($domain, &#39;sogou.com&#39;)!==false && preg_match(&#39;/query=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;SOGOU&#39;; 
        $keywords = urldecode($regs[1]); // sogou 
    }elseif(strpos($domain,&#39;so.163.com&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;NETEASE&#39;; 
        $keywords = urldecode($regs[1]); // netease 
    }elseif(strpos($domain,&#39;yodao.com&#39;)!== false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;YODAO&#39;; 
        $keywords = urldecode($regs[1]); // yodao 
    }elseif(strpos($domain,&#39;zhongsou.com&#39;)!==false && preg_match(&#39;/word=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;ZHONGSOU&#39;; 
        $keywords = urldecode($regs[1]); // zhongsou 
    }elseif(strpos($domain,&#39;search.tom.com&#39;)!==false && preg_match(&#39;/w=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;TOM&#39;; 
        $keywords = urldecode($regs[1]); // tom 
    }elseif(strpos($domain,&#39;live.com&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;MSLIVE&#39;; 
        $keywords = urldecode($regs[1]); // MSLIVE 
    }elseif(strpos($domain, &#39;tw.search.yahoo.com&#39;)!==false && preg_match(&#39;/p=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;YAHOO TAIWAN&#39;; 
        $keywords = urldecode($regs[1]); // yahoo taiwan 
    }elseif(strpos($domain,&#39;cn.yahoo.&#39;)!==false && preg_match(&#39;/p=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;YAHOO CHINA&#39;; 
        $keywords = urldecode($regs[1]); // yahoo china 
    }elseif(strpos($domain,&#39;yahoo.&#39;)!==false && preg_match(&#39;/p=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;YAHOO&#39;; 
        $keywords = urldecode($regs[1]); // yahoo 
    }elseif(strpos($domain,&#39;msn.com.tw&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;MSN TAIWAN&#39;; 
        $keywords = urldecode($regs[1]); // msn taiwan 
    }elseif(strpos($domain,&#39;msn.com.cn&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;MSN CHINA&#39;; 
        $keywords = urldecode($regs[1]); // msn china 
    }elseif(strpos($domain,&#39;msn.com&#39;)!==false && preg_match(&#39;/q=([^&]*)/i&#39;,$path,$regs)){ 
        $searchengine = &#39;MSN&#39;; 
        $keywords = urldecode($regs[1]); // msn 
    } 
 return $keywords; 
}

                   

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn