function ReplaceKeyword($kw,&$body) { global $cfg_cmspath; $maxkey = 5; $kws = explode(",",trim($kw)); //以分好為間隔符 $i=0; $karr = $kaarr = $GLOBALS['replaced'] = array(); //暫時屏蔽超鏈接 $body = preg_replace("/()(.*)(<)(/a>)/isU", '1-]-4-[-6', $body); global $dsql; $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[] = "$key"; } foreach ($karr as $key => $word) { $body = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe", "_highlight('2', $karr[$key], $kaarr[$key], '1')", $body); //echo $body." "; //恢復超鏈接 $body = preg_replace("/()/isU", '1>3<4', $body); //暫時屏蔽超鏈接 $body = preg_replace("/()(.*)(<)(/a>)/isU", '1-]-4-[-6', $body); } //恢復超鏈接 $body = preg_replace("/()/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; } |
版權(quán)聲明: 本站資源均來自互聯(lián)網(wǎng)或會員發(fā)布,如果侵犯了您的權(quán)益請與我們聯(lián)系,我們將在24小時內(nèi)刪除!謝謝!
轉(zhuǎn)載請注明: dede織夢模板下載文檔關(guān)鍵詞維護“頻率”的設置教程