01 |
function ReplaceKeyword($kw,&$body) |
03 |
global $cfg_cmspath,$dsql; |
05 |
$kws = explode(",",trim($kw)); //以分好为间隔符 |
07 |
$karr = $kaarr = $GLOBALS['replaced'] = array(); |
09 |
$body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body); |
10 |
$query="SELECT * FROM #【分隔符】@__keywords WHERE rpurl<>'' and sta=1 ORDER BY length(keyword)desc"; |
11 |
$dsql->SetQuery($query); |
13 |
while($row = $dsql->GetArray()) |
15 |
$key = trim($row['keyword']); |
16 |
$key_url=trim($row['rpurl']); |
18 |
$kaarr[] = "<u><a href='$key_url' target='_blank'>$key</a></u>"; |
20 |
foreach ($karr as $key => $word) |
22 |
$body = preg_replace("/(^|>)([^<]+)(?=<|$)/sUe", "_highlight('\\2', \$karr[$key], \$kaarr[$key], |
28 |
$body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body);//暂时屏蔽超链接 |
29 |
$body = preg_replace("/(<a(.*))(>)(.*)(<)(\/a>)/isU", '\\1-]-\\4-[-\\6', $body); |
32 |
$body = preg_replace("/(<a(.*))-\]-(.*)-\[-(\/a>)/isU", '\\1>\\3<\\4', $body); |
39 |
//高亮专用, 替换多次是可能不能达到最多次 |
40 |
function _highlight($string, $words, $result, $pre) |
42 |
global $cfg_replace_num; |
43 |
$string = str_replace('\"', '"', $string); |
44 |
if($GLOBALS['replaced'][$words] == 1){ |
47 |
if($cfg_replace_num > 0){ |
48 |
$string = preg_replace("/".preg_quote($words)."/", $result, $string, $cfg_replace_num); |
49 |
if(strpos($string, $words) !== false) |
51 |
$GLOBALS['replaced'][$words] = 1; |
54 |
else{$string = str_replace($words, $result, $string); |
|