PHP Code _php tutorial for obtaining keyword and source search engine names

Source: Internet
Author: User
Copy CodeThe code is as follows:




<title>GREENGNN Codes</title>




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" and "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 the keywords from the URL. Parameter description: The URL and the character 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 extraction of keywords
}
$keys = Explode ("", $F _skey);
$arr _key[$item [' domain '] = $keys;
}
}
echo "
 Print_r ($arr _key); 
?>

http://www.bkjia.com/phpjc/322937.html www.bkjia.com True http://www.bkjia.com/phpjc/322937.html techarticle Copy code code 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; Cha ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.