比如有“長(zhǎng)詞”、“我是大長(zhǎng)詞”、“我是小長(zhǎng)詞”,同時(shí)在一篇文章中出現(xiàn),程序會(huì)優(yōu)先使用短的詞。
打開(kāi) /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";
繼續(xù)找到
"#".preg_quote($word)."#"
改成
"#".preg_quote($word, "#")."(?!<)#"
繼續(xù)找到$body = @preg_replace_callback("#(^|>)([^<]+)(?=<|$)#sU", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body);
改成
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, "<a href='$key_url' target='_blank'><u>$key</u></a>", $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, "<a href='$key_url' target='_blank'><u>$key</u></a>", $body);
}
}
繼續(xù)找到
//高亮專用
在它上面加入
//指定替換次數(shù)功能
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);
}
完成,最終效果
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: 織夢(mèng)關(guān)鍵詞自動(dòng)內(nèi)鏈、關(guān)鍵詞長(zhǎng)短優(yōu)先級(jí)問(wèn)題、php5.5以上失效問(wèn)題解決方法