Copy codeThe Code is as follows: <! 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
// Obtain the keyword and source search engine name
$ Search_url = isset ($ _ GET ['url'])? $ _ GET ['url']: ''; // indicates the input 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: extract keywords from URLs. Parameter description: the url and the characters before the keyword.
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); // final extracted keywords
}
$ Keys = explode ("", $ F_Skey );
$ Arr_key [$ item ['domain '] = $ keys;
}
}
Echo "<pre> ";
Print_r ($ arr_key );
?>