Use PHP to display the keyword _php instance of the search engine

Source: Internet
Author: User

The following are the relevant implementation codes:

Copy Code code as follows:

<?php
/*
Plugin Name:display-search-keywords
Plugin uri:http://www.imyxiao.com/1531.html
Description: When a visitor comes to your blog through a search engine, this plugin can display the keyword of a visitor search.
version:1.0
Author:<a href= "http://www.imyxiao.com/" > Yang Xiao </a>
*/
function Unescape ($STR) {
$ret = ';
$len = strlen ($STR);
for ($i = 0; $i < $len; $i + +) {
if ($str [$i] = = '% ' && $str [$i +1] = = ' U ') {
$val = Hexdec (substr ($str, $i +2, 4));
if ($val < 0x7f)
$ret. = Chr ($val);
Else
if ($val < 0x800)
$ret. = Chr (0xc0 | ($val >> 6)) . Chr (0x80 | ($val & 0x3f));
Else
$ret. = Chr (0xe0 | ($val >> 12)) . Chr (0x80 | (($val >> 6) & 0x3f)) . Chr (0x80 | ($val & 0x3f));

$i + 5;
} else
if ($str [$i] = = '% ') {
$ret. = UrlDecode (substr ($str, $i, 3));
$i + 2;
} else
$ret. = $str [$i];
}
return $ret;
}
function Ls_get_delim ($ref) {
$search _engines = Array (
' google.com.hk ' => ' Q ',
' google.com.tw ' => ' Q ',
' go.google.com ' => ' Q ',
' google.com ' => ' Q ',
' blogsearch.google.com ' => ' Q ',
' cn.bing.com ' => ' Q ',
' one.cn.yahoo.com ' => ' P ',
' Baidu.com ' => ' wd ',
' Soso.com ' => ' W ',
' youdao.com ' => ' Q ',
' sogou.com ' => ' query '
);
$delim = false;
Judge
if (Isset ($search _engines[$ref])) {
$delim = $search _engines[$ref];
}
return $delim;
}

function Ls_get_refer () {
To determine the URL address of a previous page
$queryString = $_get[' Referer '];
$queryString = unescape ($queryString);
if (!isset ($queryString) | | ($queryString = = "))
return false;
$referer _info = Parse_url ($queryString);
$referer = $referer _info[' host '];
Remove www.
if (substr ($referer, 0, 4) = = ' www. ')
$referer = substr ($referer, 4);
return $referer;
}

function Ls_getinfo ($what) {
$referer = Ls_get_refer ();
if (! $referer)
return false;
$delimiter = Ls_get_delim ($referer);
if ($delimiter) {
$terms = Ls_get_terms ($delimiter);
if ($what = = ' Isref ' && $terms!= ') {
return true;
}
if ($what = = ' terms ') {
Echo $terms;
}
}
return false;
}

Function Yxiao_seems_utf8 ($str) {
  $length = strlen ($STR);
 for ($i = 0; $i < $length; $i + +) {
   $c = Ord ($str [$i]);
  if ($c < 0x80)
    $n = 0; # 0bbbbbbb
  elseif (($c & 0xe0) = = 0xc0) $n = 1; # 110BBBBB
  elseif ($c & 0xF0) = = 0xe0) $n = 2; # 1110bbbb
  elseif (($c & 0xf8) = 0x F0) $n = 3; # 11110BBB
  elseif (($c & 0xFC) = 0xf8) $n = 4; # 111110BB
  elseif (($c & 0xFE) = 0x FC) $n = 5; # 1111110b
  else
   return false; # does not match any model
  for ($j = 0; $ J < $n; $j + +) {# n bytes matching 10bbbbbb follow?
   if (+ + $i = = $length) | | ((Ord ($str [$i]) & 0xc0)!= 0x80))
    return false;
  }
 }
 return true;
}

Function Ls_get_terms ($d) {
 //get query value
  $queryString = $_get[' Referer '];
  $queryString = unescape ($queryString);
  $query _str = Parse_url ($queryString);
 parse_str ($query _str[query], $query _str);
  $query = $query _str[$d];
  $query = UrlDecode ($query);

$query = Str_replace ("'", ", $query);
$query = Str_replace (' ",", $query);
$query _array = Preg_split ('/[\s,\+\.] +/', $query);
$query _terms = Implode (", $query _array);
$terms = Htmlspecialchars ($query _terms);
Gbk->utf8
if (!yxiao_seems_utf8 ($terms)) {
$terms = Iconv ("GBK", "Utf-8//ignore", $terms);
}
return $terms;
}
if (Ls_getinfo (' Isref ')) {
?>
document.write (' <div id= ' Serp "><p>")
document.write (' More search results: <em><a href= "http://www.jb51.net/search?q=<?php ls_getinfo (terms);?>" ")
document.write (' title= "view <?php ls_getinfo (terms);?> search Results" rel= "nofollow" ><?php ls_getinfo (terms);? ></a></em> ')
document.write (' </p></div> ');
<?php}?>

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.