php中unserialize问题

昨天写个PHP批处理的小程序,用于数据导入后的一些数据内容格式化处理,遇到2个中文编码问题。
1个是PHP序列化的,原先表是gbk的,导入的数据表为utf8,unserialize原本serialize的数据时候出现返回null问题,google后发现是序列化编码。
$string= preg_replace(‘!s:(\d+):”(.*?)”;!se’, “‘s:’.strlen(‘$2′).’:\”$2\”;’”, $string );
$string= str_replace(“\r”, “”, $string);  //utf8 序列化处理
$extra = $string ? unserialize($string) : array();
2.取原表json格式数据后json_decode中文乱码,解决方法


<?php
$testJSON=array('name'=>'中文字符串','value'=>'test');
//echo json_encode($testJSON);
foreach($testJSON as $key=>$value) {
$testJSON[$key] = urlencode ($value);
}
echourldecode ( json_encode ($testJSON) );
?>

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论