dedecms自动给文章中的关键字加超链接完整版

,织梦dedecms自动给文章中的关键字加超链接完整版 。
在 include/arc.archives.class.php  这个文件中 有两个函数需要修改  ReplaceKeyword 和 _highlight,把这两个函数 第1014行开始到倒数第二行结束  修改为,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", '-]–[-', $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('', $karr[$key], $kaarr[$key], '')", $body);,//echo $body."<br/>";,//恢复超链接,$body = preg_replace("/(<a(.*))-]-(.*)-[-(/a>)/isU", '><', $body);,//暂时屏蔽超链接,$body = preg_replace("/(<a(.*))(>)(.*)(<)(/a>)/isU", '-]–[-', $body);,   },   //恢复超链接,$body = preg_replace("/(<a(.*))-]-(.*)-[-(/a>)/isU", '><', $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;,}, ,保存替换就可以了。
返回顶部
跳到底部

Copyright 2011-2024 南京追名网络科技有限公司 苏ICP备2023031119号-6 乌徒帮 All Rights Reserved Powered by Z-BlogPHP Theme By open开发

请先 登录 再评论,若不是会员请先 注册