织梦关键词内链、关键词长短优先级及php5.5以上失效解决方法

织梦关键词内链开启步骤
后台-系统-核心设置-关键字替换 【是】
后台-系统-其他选项-关键词替换次数 【1】
织梦关键词长短优先级问题
比如有“长词”、“我是大长词”、“我是小长词”,同时在一篇文章中出现,程序会优先使用短的词。

解决关键词长短优先级问题的方法
打开 /include/arc.archives.class.php 找到
$query = “SELECT * FROM dede_keywords WHERE rpurl<>” ORDER BY rank DESC”;
改成
$query = “SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM dede_keywords WHERE rpurl<>” ORDER BY num DESC”;

继续找到
“#”.preg_quote($word).”#”
改成
“#(?)(?!<)”.preg_quote($word).”#”
完成

PHP版本高于5.5无法使用关键词內链的解决方法
打开 /include/arc.archives.class.php 找到
$body = @preg_replace_callback(“#(^|>)([^<]+)(?=<|$)#sU”, “_highlight(‘\\2’, \$karr, \$kaarr, ‘\\1’)”, $body);
改成
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
global $cfg_replace_num;
if($cfg_replace_num > 0)
{
$query = “SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM dede_keywords WHERE rpurl<>” ORDER BY num DESC”;
$this->dsql->SetQuery($query);
$this->dsql->Execute();
while($row = $this->dsql->GetArray())
{
$key = trim($row[‘keyword’]);
$key_url=trim($row[‘rpurl’]);
$body = str_replace_limit($key, “$key“, $body, $cfg_replace_num);
}
}
else
{
$query = “SELECT char_length(keyword) AS num,aid,keyword,rpurl,rank FROM dede_keywords WHERE rpurl<>” ORDER BY num DESC”;
$this->dsql->SetQuery($query);
$this->dsql->Execute();
while($row = $this->dsql->GetArray())
{
$key = trim($row[‘keyword’]);
$key_url=trim($row[‘rpurl’]);
$body = str_replace($key, “$key“, $body);
}
}
继续找到
//高亮专用
在它上面加入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//指定替换次数功能
function str_replace_limit($search, $replace, $subject, $limit)
{
if(is_array($search))
{
foreach($search as $k=>$v)
{
$search[$k] = ‘#(?)(?!<)’. preg_quote($search[$k], ‘#’). ‘#’;
}
}
else
{
$search = ‘#(?)(?!<)’. preg_quote($search, ‘#’). ‘#’;
}
return preg_replace($search, $replace, $subject, $limit);
}

目前共 0 条评论