我们找到并打开/include/arc.archives.class.php文件,在里面找到如下代码:
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); /* foreach($kws as $k) { $k = trim($k); if($k!="") { if($i > $maxkey) { break; } $myrow = $this->dsql->GetOne("SELECT * FROM #【分隔符】@__keywords WHERE keyword='$k' AND rpurl<>'' "); if(is_array($myrow)) { $karr[] = $k; $GLOBALS['replaced'][$k] = 0; $kaarr[] = "<a href='{$myrow['rpurl']}'><u>$k</u></a>"; } $i++; } } */ $query = "SELECT * FROM #【分隔符】@__keywords WHERE rpurl<>'' ORDER BY rank DESC"; $this->dsql->SetQuery($query); $this->dsql->Execute(); while($row = $this->dsql->GetArray()) { $key = trim($row['keyword']); $key_url=trim($row['rpurl']); $karr[] = $key; $kaarr[] = "<a href='$key_url' target='_blank'><u>$key</u></a>"; } // 这里可能会有错误 $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('//2', /$karr, /$kaarr, '//1')", $body); //恢复超链接 $body = preg_replace("#(<a(.*))-/]-(.*)-/[-(//a>)#isU", '//1>//3<//4', $body); return $body; }
注意查找代码的时候先手动去掉代码里面的【分隔符】字样!
找到后将其替换为如下代码:
function ReplaceKeyword($kw,&$body) { global $cfg_cmspath,$dsql; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好为间隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暂时屏蔽超链接 $body = preg_replace("/(<a(.*))(>)(.*)(<)(//a>)/isU", '//1-]-//4-[-//6', $body); $query="SELECT * FROM #【分隔符】@__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[] = "<u><a href='$key_url' target='_blank'>$key</a></u>"; } 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; } }else{$string = str_replace($words, $result, $string);}return $pre.$string;}
注意手动去掉代码里面的【分隔符】字样!
替换完成后保存即可,然后生成一下文章内容试试。
新闻热点
疑难解答