我們找到并打開(kāi)/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(); //暫時(shí)屏蔽超鏈接 $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>"; } // 這里可能會(huì)有錯(cuò)誤 $body = @preg_replace("#(^|>)([^<]+)(?=<|$)#sUe", "_highlight('\\2', \$karr, \$kaarr, '\\1')", $body); //恢復(fù)超鏈接 $body = preg_replace("#(<a(.*))-\]-(.*)-\[-(\/a>)#isU", '\\1>\\3<\\4', $body); return $body; } |
注意查找代碼的時(shí)候先手動(dòng)去掉代碼里面的【分隔符】字樣!
找到后將其替換為如下代碼:
function ReplaceKeyword($kw,&$body) { global $cfg_cmspath,$dsql; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好為間隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暫時(shí)屏蔽超鏈接 $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/>"; //恢復(fù)超鏈接 $body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body);//暫時(shí)屏蔽超鏈接 $body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body); } //恢復(fù)超鏈接 $body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body); return $body; } } //End Archives //高亮專用, 替換多次是可能不能達(dá)到最多次 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; } |
注意手動(dòng)去掉代碼里面的【分隔符】字樣!
替換完成后保存即可,然后生成一下文章內(nèi)容試試。
版權(quán)聲明: 本站資源均來(lái)自互聯(lián)網(wǎng)或會(huì)員發(fā)布,如果侵犯了您的權(quán)益請(qǐng)與我們聯(lián)系,我們將在24小時(shí)內(nèi)刪除!謝謝!
轉(zhuǎn)載請(qǐng)注明: dedecms關(guān)鍵詞維護(hù)里面字?jǐn)?shù)多的詞優(yōu)先字?jǐn)?shù)少的詞的解決辦法