使用json_encode的时候,中文会被转码成为unicode格式,解决这个问题,主要有以下三种方法:
1.
<?php echo json_encode("叨嘛",JSON_UNESCAPED_UNICODE);
<?php $array = array('doma' => urlencode("叨嘛")); $array = json_encode($array); echo urldecode($array);
<?php $string = 'result: {"errorcode":"1","errormsg":"u65b0u589eu5931u8d25uff01","result":""}'; function unicode($str, $encoding = null) { return preg_replace_callback ( '/\\u([0-9a-fA-F]{4})/u', create_function ( '$matches', 'return mb_convert_encoding(pack("H*", $matches[1]), "utf-8", "UTF-16BE");' ), $str ); } echo unicode ( $string );
第三种方式是在读取的时候对unicode编码进行转码
不理解的地方:为什么正则表达式是这样写的?\\如何解释,无法匹配呀
回调函数
立即学习“PHP免费学习笔记(深入)”;
以上就介绍了汉字转unicode php-关于unicode的转码,包括了汉字转unicode方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号