Displays the keyword of the visitor search on the first page of the visitor from the search engine, and makes some changes to improve the interactivity of the website, such as displaying the other articles related to this keyword
.
The following is the relevant implementation code: the code is as follows: <?php/* Plugin name:display-search-keywords Plugin uri:http://www.imyxiao.com/1531.html descripti On: When visitors come through the search engine to your blog, this plugin can display the key words of the 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; &NBSP} else   $ret. = $str [$i]; &NBSP} 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; //Judgment if (isset ($search _engines[$ref])) { $delim = $search _engines[$ref]; return $delim; } function Ls_get_refer () { //to determine the URL address of the previous page $queryString = $_get[' Referer ']; $queryString = UN Escape ($queryString); if (!isset ($queryString) | | ($queryString = = ")) return false; $referer _info = Parse_url ($queryString); $referer = $referer _info[' host ']; //to 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; $de Limiter = Ls_get_delim ($referer); if ($delimiter) { $terms = ls_get_terms ($delimiter); if ($what = = ' Isref ' && $terms!= ') {& nbsp 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) = = 0xF0) $n = 3; # 11110bbb ElseIf (($c & 0xFC) = = 4 (= 0xf8) $n # 111110BB ElseIf (($c & 0xFE) = 0xFC) $n = 5; # 1111110b Else return false; # does not match no 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); &NBSP} 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}?>