使用php显示搜索引擎来的关键词

时间:2021-05-25

以下是相关实现代码:

复制代码 代码如下:
<?php
/*
Plugin Name: display-search-keywords
Plugin URI: http://' => 'query'
);
$delim = false;
// 判断
if (isset ($search_engines[$ref])) {
$delim = $search_engines[$ref];
}
return $delim;
}

function ls_get_refer() {
// 判断前一页面的 URL 地址
$queryString = $_GET['referer'];
$queryString = unescape($queryString);
if (!isset ($queryString) || ($queryString == ''))
return false;
$referer_info = parse_url($queryString);
$referer = $referer_info['host'];
//去除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) == 0xF0) $n = 3; # 11110bbb
elseif (($c & 0xFC) == 0xF8) $n = 4; # 111110bb
elseif (($c & 0xFE) == 0xFC) $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) {
//取得查询值
$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('更多搜索结果:<em><a href="https://www.jb51.net/search?q=<?php ls_getinfo(terms); ?>" ')
document.write('title="查看<?php ls_getinfo(terms); ?>的搜索结果" rel="nofollow"><?php ls_getinfo(terms); ?></a></em>')
document.write('</p></div>');
<?php } ?>

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章