|
|
Subject:
Specification of PHP's serialize()
Category: Computers > Programming Asked by: shane43-ga List Price: $5.00 |
Posted:
02 Aug 2003 22:58 PDT
Expires: 01 Sep 2003 22:58 PDT Question ID: 238363 |
The following was inserted into my db as a 2-D array that was serialized for storage: a:5:{i:1;a:3:{s:8:"formname";s:5:"Fname";s:10:"commonname";s:10:"First Name";s:5:"value";s:8:"Mercedes";}i:2;a:3:{s:8:"formname";s:5:"Lname";s:10:"commonname";s:9:"Last Name";s:5:"value";s:8:"OConnor";}i:3;a:3:{s:8:"formname";s:5:"Phone";s:10:"commonname";s:5:"Phone";s:5:"value";s:12:"818-893-4226";}i:4;a:3:{s:8:"formname";s:5:"Email";s:10:"commonname";s:13:"Email Address";s:5:"value";s:18:"moandto@seiu99.net";}i:5;a:3:{s:8:"formname";s:6:"Income";s:10:"commonname";s:6:"Income";s:5:"value";s:16:"$3,000 PER MONTH";}} However, when I try to unserialize it, it won't create the array again. Most 99.9% of entries are fine, but every once in a while one gets messed up like this one. Does anyone know what could be causing this? or...do you know where I could go to find out the definition of serialization so that I can see where it differs from the spec? | |
| |
| |
|
|
Subject:
Re: Specification of PHP's serialize()
Answered By: joseleon-ga on 06 Aug 2003 01:43 PDT Rated: |
Hello: I have found what is the problem, let's look at this part of the array: 5:"value";s:8:"OConnor";}i:3;a:3:{ When php serializes an object, s:8 means a string of 8 characters and when you remove the single (') quote from that value (O'Connor) *after* serialize it, the string has just 7 chars, not 8, this is why unserialize can't recover the string. A possible solution would be to replace all single(') quotes and double(") quotes by \' and \" before save the string to the database, if you post here the piece of code, I will do it for you. Regards. |
shane43-ga
rated this answer:
Thanks so much. The cause of the error was exactly as you said, however I could not get your suggestion to work (but that wasn't my question...I just wanted to know why, which you answered). Thanks! |
|
Subject:
Re: Specification of PHP's serialize()
From: vijayanand-ga on 03 Aug 2003 02:12 PDT |
http://in.php.net/manual/en/function.serialize.php |
Subject:
Re: Specification of PHP's serialize()
From: shane43-ga on 03 Aug 2003 10:57 PDT |
Yeah, I know about that page, but what I am after is the exact definition of how to serialize something. As in, I need to know what "a:5:{i:1;a:3:{s:8:" means so that I can see where the above differs from the accepted format. Thanks, Shane |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |