目前,我正在尝试寻找一种解码来编码包含unicode字符的高棉语字符,高棉语.我尝试过使用php内置函数urlencode()并给出结果:例如:http://www.example.com/? kwd = Mac + Book + Pro +នៅប្រទេសយើង
虽然我使用Google搜索进行了测试,但结果是:https: //www.google.com.kh/#hl=en&sclient=psy-ab&q=Mac+Book+Pro+%E1%9E%93%E1%9F%85 %E1%9E%94%E1%9F%92%E1%9E%9A%E1%9E%91%E1%9F%81%E1%9E%9F%E1%9E%99%E1%9E%BE%E1 %9E%84&OQ = MAC +书+临+%E1%9E%93%E1%9F%85%E1%9E%94%E1%9F%92%E1%9E%9A%E1%9E%91%E1%9F %81%E1%9E 9F%%E1%9E%99%E1%9E%BE%E1%9E%84
怎么做?希望有人在这里帮助我.提前致谢!
And*_*ndy 10
对于UTF-8,您可以使用:
urlencode(utf8_encode($string)); //for encoding
utf8_decode(urldecode($string)); //for decoding
Run Code Online (Sandbox Code Playgroud)
对于UTF-16,您可以使用此功能(来自http://php.net中 "urlencode"的注释):
function utf16_urlencode ( $str ) {
# convert characters > 255 into HTML entities
$convmap = array( 0xFF, 0x2FFFF, 0, 0xFFFF );
$str = mb_encode_numericentity( $str, $convmap, "UTF-8");
# escape HTML entities, so they are not urlencoded
$str = preg_replace( '/&#([0-9a-fA-F]{2,5});/i', 'mark\\1mark', $str );
$str = urlencode($str);
# now convert escaped entities into unicode url syntax
$str = preg_replace( '/mark([0-9a-fA-F]{2,5})mark/i', '%u\\1', $str );
return $str;
}
Run Code Online (Sandbox Code Playgroud)