2012-12-23 点击看最新版本:http://blog.csdn.net/default7/article/details/8373293
———————————————————————————————————————————————
PHP搜索关键词描红函数:
function SearchReplaceKw($string,$sokw=''){
if(empty($sokw) || empty($string)) return $string;
$badString = array(
'~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '-', '+', '[', ']',
':', ';', '\'', '"', '|', '\\', ',', '.', '?', '/', '<', '>',
);
$sokw = str_replace($badString,' ',$sokw);
$sokw = preg_replace('/\s+/','|',$sokw);
return preg_replace("/($sokw)/",'<font color="red">\\1</font>',$string);
}
因为不能发布,所有我直接粘贴了。
截图: