unicode转中文时可以使用json_decode()函数实现。
中文转unicode时需要对字符串转换成UCS-4编码,再转成16进制,再从16进制转换成10进制加上前缀来实现中文转unicode编码。
一、unicode转中文
二、中文转unicode
//中文转unicode function UnicodeEncode($str){ //split word preg_match_all('/./u',$str,$matches); $unicodeStr = ""; foreach($matches[0] as $m){ //拼接 $unicodeStr .= "".base_convert(bin2hex(iconv('UTF-8',"UCS-4",$m)),16,10); } return $unicodeStr; } $str = "新浪微博"; echo UnicodeEncode($str);欢迎分享,转载请注明来源:内存溢出
评论列表(0条)