The principle is to extract keywords from the URL. Parameter description: URL and keyword before the character, and then processing and source to judge is the search engine, so save to the data on the line.
<?php Tutorial
//
$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);
?>
<form action= "index.php" method= "Get" >
<input name= "url" size= "><button type=" Submit ">go</button>
</form>