当前位置:网站首页 > 软件教程 > 正文

dedecms织梦CMS怎么给自动给文章中的关键字加超链接?

作者:admin发布时间:2021-11-03分类:软件教程浏览:评论:0


导读:在 include/arc.archives.class.php  这个文件中有两个函数需要修改  ReplaceKeyword和_highlight把这两个函数第1014行开始到倒数第二行结束  修改为functionReplaceKeyword($kw,&$body){global$cfg_cmspath;$maxkey=5;$kws=exp

在 include/arc.archives.class.php  这一文档中 有两个涵数必须改动  ReplaceKeyword 和 _highlight

把这两个涵数 第一014行逐渐到最后第二行完毕  改动为

function ReplaceKeyword($kw,&$body)
{
global $cfg_cmspath;
$maxkey = 5;
$kws = explode(",",trim($kw)); //以分得为间隔符
$i=0;
$karr = $kaarr = $GLOBALS['replaced'] = array();

   //临时屏蔽掉网页链接
$body = preg_replace("/(<a(.*))(>)(.*)(<)(/a>)/isU", '\1-]-\4-[-\6', $body);

   global $dsql;
$query="SELECT * FROM dede_keywords WHERE rpurl<>'' and sta=1 ORDER BY length(keyword)desc";
$dsql->SetQuery($query);
$dsql->Execute();
while($row = $dsql->GetArray())
{
$key = trim($row['keyword']);
$key_url=trim($row['rpurl']);
$karr[] = $key;
$kaarr[] = "<b><a href='$key_url' target='_blank'>$key</a></b>";
}
foreach ($karr as $key => $word)
{

    $body = preg_replace("/(^|>)([^<] )(?=<|$)/sUe", "_highlight('\2', $karr[$key], $kaarr[$key], '\1')", $body);
//echo $body."<br/>";

//修复网页链接
$body = preg_replace("/(<a(.*))-]-(.*)-[-(/a>)/isU", '\1>\3<\4', $body);
//临时屏蔽掉网页链接
$body = preg_replace("/(<a(.*))(>)(.*)(<)(/a>)/isU", '\1-]-\4-[-\6', $body);

   }

   //修复网页链接
$body = preg_replace("/(<a(.*))-]-(.*)-[-(/a>)/isU", '\1>\3<\4', $body);
return $body;
}

}//End Archives

//高亮度专用型, 更换数次是很有可能不可以做到最数次
function _highlight($string, $words, $result, $pre)
{
global $cfg_replace_num;
$string = str_replace('"', '"', $string);

if($GLOBALS['replaced'][$words] == 1)
{
return $pre.$string;
}

if($cfg_replace_num > 0)
{
$string = preg_replace("/".preg_quote($words)."/", $result, $string, $cfg_replace_num);
if(strpos($string, $words) !== false)
{
$GLOBALS['replaced'][$words] = 1;
//echo $words;
}

}
else
{
$string = str_replace($words, $result, $string);
}

return $pre.$string;
}

 

储存更换就可以了

标签:dedecms


欢迎 发表评论: