function keywords($url){
$spier=array('baidu.'=>'百度','google.'=>'谷歌','soso.'=> '搜搜','sogou.'=>'搜狗','www.haosou.com'=>'360');
$q=array('百度'=>'/wd=([^&]*)/i','谷歌'=>'/q=([^&]*)/i ','360'=>'/q=(.*)/i','搜狗'=>'/query=([^&]*)/i','搜搜'=>'/w=([^&]*)/i');
foreach($spier as $k=>$v){
if(strpos($url,$k)){
preg_match("{$q[$v]}",$url,$b);
if($v=='搜搜'||$v=='搜狗'){
$keywords=iconv('GBK','UTF-8',urldecode($b[1]));
}else{
$keywords=urldecode($b[1]);
}
echo "<br>来自{$v}的关键字:".$keywords.'<br>';
}
}
}
调用方法:echo $this->keywords($_SERVER['HTTP_REFERER']);//$_SERVER['HTTP_REFERER']获取上一级的url