php中获取关键词及所属来源搜索引擎名称的代码

yipeiwu_com5年前PHP代码库
复制代码 代码如下:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>greengnn codes</title>
</head>
<body>
<form action="index.php" method="get">
<input name="url" size="80"><button type="submit">GO</button>
</form>

<?php
//获取关键词及所属来源搜索引擎名称

$search_url = isset($_GET['url'])?$_GET['url']:''; //代表传入的地址
/*$search_url = urldecode($search_url);
print_r($search_url);
*/

$config = array(
"s1"=>array(
"domain" => "google.com",
"kw" => "q",
"charset" => "utf-8"
),
"s3"=>array(
"domain" => "google.cn",
"kw" => "q",
"charset" => "utf-8"
),
"s4"=>array(
"domain" => "baidu.com",
"kw" => "wd",
"charset" => "gbk"
),
"s5"=>array(
"domain" => "soso.com",
"kw" => "q",
"charset" => "utf-8"
),
"s6"=>array(
"domain" => "yahoo.com",
"kw" => "q",
"charset" => "utf-8"
),
"s7"=>array(
"domain" => "bing.com",
"kw" => "q",
"charset" => "utf-8"
),
"s8"=>array(
"domain" => "sogou.com",
"kw" => "query",
"charset" => "gbk"
),
"s9"=>array(
"domain" => "youdao.com",
"kw" => "q",
"charset" => "utf-8"
),
);

//函数作用:从url中提取关键词。参数说明:url及关键词前的字符。
function get_keyword($url,$kw_start)

{
$start = stripos($url,$kw_start);
$url = substr($url,$start+strlen($kw_start));
$start = stripos($url,'&');
if ($start>0)
{
$start=stripos($url,'&');
$s_s_keyword=substr($url,0,$start);
}
else
{
$s_s_keyword=substr($url,0);
}
return $s_s_keyword;
}

$arr_key = array();
foreach($config as $item){
$sh = preg_match("/\b{$item['domain']}\b/",$search_url);
if($sh){
$query = $item['kw']."=";

$s_s_keyword = get_keyword($search_url,$query);
$F_Skey=urldecode($s_s_keyword);
if($item['charset']=="utf-8"){
$F_Skey=iconv( "UTF-8","gb2312//IGNORE",$F_Skey); //最终提取的关键词
}
$keys = explode(" ",$F_Skey);
$arr_key[$item['domain']] = $keys;
}
}
echo "<pre>";
print_r($arr_key);
?>

相关文章

php 判断数组是几维数组

复制代码 代码如下:<?php/** * 返回数组的维度 * @param  [type] $arr [description] * @re...

php排序算法(冒泡排序,快速排序)

冒泡排序实现原理 ① 首先将所有待排序的数字放入工作列表中。② 从列表的第一个数字到倒数第二个数字,逐个检查:若某一位上的数字大于他的下一位,则将它与它的下一位交换。 ③ 重复步骤②,直...

jQuery 源码分析笔记

jQuery的宗旨是Write Less, Do More。它对JavaScript的开发风格侵入性不如YUI那么强,当然也不如Dojo和YUI如此庞大。它极大的简化了JavaScrip...

php中使用Curl、socket、file_get_contents三种方法POST提交数据

抓取远程内容,之前一直都在用file_get_content函数,其实早就知道有curl这么一个好东西的存在,但是看了一眼后感觉使用颇有些复杂,没有file_get_content那么简...

Wordpress 相册插件 NextGEN-Gallery 添加目录将中文转为拼音的解决办法

NextGEN Gallery是Wordpress中著名的相册插件,遗憾的是不支持中文等unicode字符,本文将介绍如何将目录转换为拼音(添加图集时)。 以NextGEN 1.6.2为...