简体   繁体   English

在PHP中使用反序列化时出错?

[英]Error when using unserialize in php?

$info='a:1:{s:10:"2G Network";s:22:"GSM 900 / 1800 / 1900 ";}';
$info1 = unserialize($info);
print_r($info1);

When run code in firebug get error: 在Firebug中运行代码时出现错误:

Notice: unserialize() [<a href='function.unserialize'>function.unserialize</a>]: Error at offset 0 of 65 bytes in...

How to fix it ? 如何解决?

$info='a:38:{s:10:"2G Network";s:22:"GSM 900 / 1800 / 1900 ";}'; is not properly serialized. 没有正确序列化。

The format for an array is as follows: 数组的格式如下:

a: number of items :{ collection of elements }; a: 项目数量 :{ 元素集合 };

You one element in your array (2G Network => GSM 900 / 1800 / 1900). 您是阵列中的一个元素(2G网络=> GSM 900/1800/1900)。 All the rest is fine, and the following unserializes properly: 其余的一切都很好,以下代码可以正确地反序列化:

a:1:{s:10:"2G Network";s:22:"GSM 900 / 1800 / 1900 ";}
use utf8_encode and utf8_decode..
like..

$str = utf8_encode($str); 

$str= unserialize($str); 

$str= utf8_decode($str);  

I think this one is help to resolve your problem : 我认为这有助于解决您的问题:

<?php

$info = serialize(array('2G Network','GSM 900 / 1800 / 1900'));
(or)
$info='a:1:{s:10:"2G Network";s:22:"GSM 900 / 1800 / 1900 ";}';

$info1 = unserialize($info);
// Show the unserialized data;
print_r($info1);
?>

For Your Functional Reference click this for example. 对于您的功能参考,请单击此示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM