Code to get keyword and source search engine name in PHP
Last Update:2017-02-28
Source: Internet
Author: User
Copy Code The code is as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<TITLE>GREENGNN codes</title>
<body>
<form action= "index.php" method= "Get" >
<input name= "url" size= "><button type=" Submit ">GO</button>
</form>
<?php
Get keyword and source search engine name
$search _url = isset ($_get[' url ')? $_get[' URL ']: '; Represents an incoming address
/* $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"
),
);
Function: Extracts keywords from the URL. Parameter description: URL and keyword before the character.
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); The final extract of the keyword
}
$keys = Explode ("", $F _skey);
$arr _key[$item [' domain ']] = $keys;
}
}
echo "<pre>";
Print_r ($arr _key);
?>