简体   繁体   English

PHP-使用反序列化时获取bool(false)

[英]PHP - Getting bool(false) when using unserialize

The $response I am getting from the server is shown below:- 我从服务器获得的$ response如下所示:

a:2:{s:3:"Car";s:0:"";s:9:"JbMessage";s:0:"";s:10:"PreBooking";s:0:"";s:6:"pickup";s:36:"TOWNEND CENTRE; WORKSOP ROAD S26 4WB";s:4:"Zone";s:8:"OOA_EAST";s:7:"dropoff";s:41:"PRINCE WILLIAM ROAD; LOUGHBOROUGH LE115GU";s:8:"PassName";s:0:"";s:8:"Customer";s:0:"";s:9:"AccountNo";s:0:"";s:8:"DocketNo";s:0:"";s:3:"Tel";s:0:"";s:7:"CarType";s:3:"Car";s:8:"Comments";s:0:"";s:9:"Comments1";s:0:"";s:9:"OrderedBy";s:0:"";s:12:"Autorization";s:0:"";s:8:"BookedBy";s:0:"";s:15:"BookingDateTime";s:19:"11042014 09:31:49";s:10:"Dispatched";s:10:"01011900";s:5:"Miles";s:5:"43.21";s:6:"Driver";s:0:"";s:7:"Payment";s:4:"Cash";s:8:"Priority";s:1:"1";s:4:"Done";s:1:"C";s:11:"JourneyType";s:0:"";s:12:"NoPassengers";s:1:"1";s:5:"Drops";s:0:"";s:2:"TM";s:0:"";s:14:"BookingMethode";s:5:"Phone";s:7:"Editted";s:0:"";s:9:"EdittedOn";s:10:"01011900";s:9:"FromHouse";s:0:"";s:6:"FromNo";s:0:"";s:10:"FromStreet";s:28:"TOWNEND CENTRE; WORKSOP ROAD";s:10:"FromZoneNo";s:2:"73";s:12:"FromPostCode";s:7:"S26 4WB";s:10:"FromEWGrid";s:0:"";s:12:"emailAddress";s:0:"";s:9:"FromNotes";s:0:"";s:11:"AutorizedBy";s:0:"";s:7:"ToHouse";s:0:"";s:4:"ToNo";s:0:"";s:8:"ToStreet";s:33:"PRINCE WILLIAM ROAD; LOUGHBOROUGH";s:8:"ToZoneNo";s:2:"73";s:10:"ToPostCode";s:7:"LE115GU";s:6:"Mobile";s:0:"";s:7:"ToNotes";s:0:"";s:8:"ToEWGrid";s:0:"";s:11:"BookingDate";s:19:"11042014 09:31:00";s:10:"DriverFare";s:4:"71.5";s:12:"CustomerFare";s:4:"71.5";s:12:"DriverExtras";s:1:"0";s:14:"CustomerExtras";s:1:"0";s:11:"WaitingTime";s:0:"";s:

I am doing the following:- 我正在执行以下操作:

$response = strip_tags($response);
$deserializedAddressArray = stripslashes($response);
$deserializedAddressArray = unserialize($response);

var_dump($deserializedAddressArray);

However, I don't understand why $deserializedAddressArray is coming back as bool(false), any ideas? 但是,我不明白为什么$deserializedAddressArray会以bool(false)的形式返回,有什么想法吗?

Your serialize data is not valid. 您的序列化数据无效。 Please make sure that you give the right string. 请确保您输入正确的字符串。 there is no ending bracket in it for example valid serialize string 其中没有结尾括号,例如有效的序列化字符串

 a:1:{s:4:"name";s:6:"testing";}

This is the valid serialize string with the ending bracket 这是带结尾括号的有效序列化字符串

So we know the string is invalid, but as a stab in the dark this may have one of the following causes: 因此,我们知道该字符串无效,但作为暗中的刺,这可能是以下原因之一:

  • If the string is stored against a table, then the column type should be long text to ensure the highly variable string length will be stored. 如果字符串是针对表存储的,则列类型应为long text以确保将存储高度可变的字符串长度。

  • If any of the data being serialized contains non-encoded characters, or multi-byte characters, it is possible for the string to end with one of those characters. 如果要序列化的任何数据包含未编码的字符或多字节字符,则字符串可能以这些字符之一结尾。 PHP unserialize fails with non-encoded characters? PHP反序列化失败,并出现非编码字符?

Got this working, the problem was at the start a:2: - as soon as I changed this to a:77: it started working. 解决了这个问题,问题开始于a:2: -一旦我将其更改为a:77:它开始起作用。

This is because there are 77 values in the response. 这是因为响应中有77个值。

You have to increase the size of your table in the database. 您必须增加数据库中表的大小。 Example: varchar 255 to varchar 510 Or Change type to TEXT. 示例:将varchar 255更改为varchar 510或将类型更改为TEXT。

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

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