// Example use: $spanned = codeWords($string_containing_keywords);// My site: andrew.dx.am// Using colour==blue, but different arrays of words and different // colours can be added.function onlyWholeWords(&$value, $key) {// Ignores words after // comment delimiters.//$value = "/\b(" . $value . ")\b/"; // doesn't handle comments//$value = "/^(?:(?!\/\/).)*\K\b(" . $value . ")\b/"; // \K lookbehind alternative is not supported in $row) { list($kwd, $url) = $row; for($j=$i+1; $j$subKwd = $linkMap[$j][0]; //如果包含其他关键字,暂时替换成其他字符串 if(strpos($kwd, $subKwd) !== false) { $tmpKwd = '{'.md5($subKwd).'}'; $kwd = str_replace($subKwd, $tmpKwd, $kwd); $tmpKwds[$tmpKwd] = $subKwd; } } //把文字替换成链接 $str = preg_replace('/('.$row[0].')/sui', ''.$kwd.'', $str, $count); }//把代替子关键字的字符串替换回来 foreach($tmpKwds as $tmp=>$kwd) { $str = str_replace($tmp, $kwd, $str); } return $str; } ?>复制代码 09-18 23:09