网站首页 > 知识剖析 正文
问题描述:如下是我序列化数组之后的数据,但是取出来之后,反序列化不了。
$a = 'a:2:{i:1;a:5:{s:8:"pic_sort";i:2;s:9:"pic_check";b:1;s:10:"pic_select";i:56;s:8:"pic_path";s:1:"ergregerg";s:8:"pic_link";s:2:"wesaddasd";}i:2;a:5:{s:8:"pic_sort";i:2;s:9:"pic_check";b:0;s:10:"pic_select";i:57;s:8:"pic_path";s:10:"4444";s:8:"pic_link";s:14:"http://fafa.com";}}';
print_r(unserialize($a));
问题原因:应该是从数据库中取出的编码和页面的编码不一致造成的。
解决方案:自定义如下的函数调用就可以了
print_r(mb_unserialize($a));
function mb_unserialize($serial_str) {
$out = preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'", $serial_str );
return unserialize($out);
}
猜你喜欢
- 2024-11-20 laravel5.0在linux下解决.htaccess无效和去除index.php的问题
- 2024-11-20 面向对象之里式替换法则
- 2024-11-20 如何保证API接口安全?
- 2024-11-20 wamp怎么升级php版本
- 2024-11-20 Wordpress建站教程:去除修改管理员邮箱时的邮件验证步骤
- 2024-11-20 给PHP开发者的九条建议
- 2024-11-20 PHP 数学相关函数
- 2024-11-20 Update The PHP Version In XAMPP On Windows
- 2024-11-20 3分钟短文 | PHP 删除字符串最末一个字符,你用的什么方法?
- 2024-11-20 PHP使用mongo-php-library操作MongoDB数据库的方法
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)