最近正在优化搜索功能,请教下官方工程师encode_search_code方法,
把UTF-8转成UTF-16的原因。
###class search_index_class extends AWS_MODEL
	public function encode_search_code($string)
	{
		if (is_array($string))
		{
			$string = implode(' ', $string);
		}
		
		$string = convert_encoding($string, 'UTF-8', 'UTF-16');
		
		for ($i = 0; $i < strlen($string); $i++, $i++)
    	{ 
    		$code = ord($string{$i}) * 256 + ord($string{$i + 1});
    		
    		if ($code == 32)
    		{
    			$output .= ' ';
    		}
    		else if ($code < 128)
    		{ 
    			$output .= chr($code); 
    		}
    		else if ($code != 65279)
    		{ 
    			$output .= $code;
    		}
    	}
    	return htmlspecialchars($output);
	}
                                     阅读全文
                                
                                
                                     收起全文