[英]Highlight multiple keywords in search (non-english characters)
您确定要搜索Unicode字符吗? \\ w仅匹配[a-zA-Z0-9_]。
例如,这匹配波斯数字:
preg_match( "/[^\x{06F0}-\x{06F9}\x]+/u" , '۱۲۳۴۵۶۷۸۹۰' );
来源: http : //php.net/manual/en/function.preg-match.php
只需使用要匹配的字符创建一个字符类。
页面加载所需的编码后,最好使用JS来实现:
function paint_keys( str_to_replace , words ){
temp_reg = str_to_replace;
if( /\s/g.test( temp_reg ) ) temp_reg = temp_reg.split( " " ); // Breaking our searching keywords into an array;
else return words.split( temp_reg ).join( "<span class='painted'>" + temp_reg + "</span>" );
for( z = 0 ; z < temp_reg.length ; z++ ){
if( temp_reg[ z ] != "" ) words = words.split( temp_reg[ z ] ).join( "<span class='painted'>" + temp_reg[ z ] + "</span>" );
}
return words;
}
当然,您可以根据需要替换<span class='painted'>" + temp_reg + "</span>
。
如果您只需要使用php来完成它-使用通过explode( "\\s" , $words );
破坏键来排列数组的原理explode( "\\s" , $words );
-这只会为您提供一个符号数组,然后循环为该数组中的每个单词替换字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.