• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2130
  • Last Modified:

PHP unserialize returns empty array

Hello,

I use serialize() to store an (maximum of three levels deep) array into a database field, which until now worked very fine. The data that is being stored, is mainly coming from a richt-text editor. The whole thing is used in a tool i have created for a client, which worked just very fine for almost a year now. However, just today my client has stored some information that for some reason can not be unserialized. PHP unserialize() just returns me nothing. An empty array, that is.

I now need to restore the information, so that it can be unserialized again, but still after hours of trying, i do not seem to find the error, nor do i seem to see any reason for the problem to occur.

My actual question is: how can i restore the information most efficiently? Is there any function that can analyze the broken data? Or an alternative to unserialize() that will not just return false but at least tell me where the problem resides, where it stops parsing?

I am looking forward to suggestions. Thank you very much.

Ps.: I do know about quoting problems and i can say for sure that it is none of those. In fact my client uses single and double quotes in his data frequently, but it has never been a problem. I made the script solid in that relation.
0
spiritwithin
Asked:
spiritwithin
  • 4
  • 4
1 Solution
 
TeRReFCommented:
Can you give an example of the serialized data?
0
 
JakobACommented:
Have you done a var_dump(...) on the serialized string ? It should at least give you an idea about what he stored.
0
 
spiritwithinAuthor Commented:
TeRReF: Thanks for replying. The serialized data is just normal text/html data.

JakobA: Thanks for replying. var_dump() gives me as much as a print_r() - which is, unfortunately - nothing. Of course i took a look at the serialized data. It looks quite normal. The serialization closes correctly with the final bracket "}" and everything looks ok. Still it wont unserialize().
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
JakobACommented:
quotes or unbalanced bracketing are prime suspects, but without a specific example to look at all we can do is guess.
Quoting TeRReF: Can you give an example of the serialized data?
0
 
spiritwithinAuthor Commented:
Alright. But i do not assume that this will really be of help, cause i cant just post of all of it here and you can not use only parts of it for testing (the full version is complete of course, fully enclosed by the brackets) :

a:17:{i:0;a:6:{s:5:'_type';s:5:'topic';s:3:'_id';i:0;s:4:'code';s:0:'';s:4:'text';a:1:{s:7:'content';s:0:'';}s:5:'topic';a:1:{s:7:'content';s:82:'<p><strong><u><font color='#ff6600' size='2'>RAUS-Verkauf!</font></u></strong></p>';}s:3:'img';s:0:'';}i:1;a:6:{s:5:'_type';s:3:'img';s:3:'_id';i:1;s:4:'code';s:0:'';s:4:'text';a:1:{s:7:'content';s:0:'';}s:5:'topic';a:1:{s:7:'content';s:0:'';}s:3:'img';s:21:'163__RAUS-Verkauf.gif';}i:2;a:6:{s:5:'_type';s:11:'last_minute';s:3:'_id';i:2;s:4:'code';s:0:'';s:4:'text';a:1:{s:7:'content';s:4592:'<p><span style='FONT-SIZE: 9pt; COLOR: #0067a6; FONT-FAMILY: Arial'>XXX XXXX bleibt seinem Motto treu und bietet dir erneut die <strong>besten Preise</strong>.<br />Da&nbsp;bleibt&nbsp;noch mehr Geld in deiner Bordkasse!<br /><br /></span><strong><span style='COLOR: red; FONT-FAMILY: Arial'><font size='3'><font color='#0067a6'>Buche jetzt und spare bis zu</font> </font><font size='6'>25%.</font></span></strong><b><span style='COLOR: red; FONT-FAMILY: Arial'><br /></span></b><span style='FONT-SIZE: 9pt; COLOR: #0067a6; FONT-FAMILY: Arial'><br />Unter dem Motto<strong> 'RAUS-Verkauf'</strong> bieten wir dir auch noch die <br /><strong>letzten freien Yachten</strong> um sensationelle Preise an. <br /><br />Hier ein kleiner Auszug der aktuellsten </span><strong><span style='COLOR: red; FONT-FAMILY: Arial'><font size='3'>Schn├Ąppchen</font></span></strong><span style='FONT-SIZE: 9pt; COLOR: #0067a6; FONT-FAMILY: Arial'>:
<p></p></span></p>

-------------------

Just like that.

Ps.: The single quotes get replaced by double quotes before unserialize() is called, so this is not the matter.
0
 
JakobACommented:
How about taking it a bit at a time. The serializing rules are nicely obvious so it should not be too hard.

Like here are the first 2 entries in serialized form:

a:2:{i:0;a:6:{s:5:'_type';s:5:'topic';s:3:'_id';i:0;s:4:'code';s:0:'';s:4:'text';a:1:{s:7:'content';s:0:'';}s:5:'topic';a:1:{s:7:'content';s:82:'<p><strong><u><font color='#ff6600' size='2'>RAUS-Verkauf!</font></u></strong></p>';}s:3:'img';s:0:'';}i:1;a:6:{s:5:'_type';s:3:'img';s:3:'_id';i:1;s:4:'code';s:0:'';s:4:'text';a:1:{s:7:'content';s:0:'';}s:5:'topic';a:1:{s:7:'content';s:0:'';}s:3:'img';s:21:'163__RAUS-Verkauf.gif';}}

if they unserialize correctly try the next 2, etc, until you find the data making trouble.

That is a pretty huge string by the way. do you have error_reporting enabled so you get iinformed in case it is just a basic error like 'out of memory, aborting operation' ?
0
 
JakobACommented:
this string is a bit suspect:

s:82:'<p><strong><u><font color='#ff6600' size='2'>RAUS-Verkauf!</font></u></strong></p>';

with '-s both in and around the string are you sure the single to double quote substitution gets done correctly there ?
0
 
spiritwithinAuthor Commented:
Sorry for letting you wait, but i took a day off on the weekend.

Regarding the suspect string from above, i have checked the unserialize() - function and also checked other sets of data that just work fine. It appears that unserialize() does'nt mind the quotes inside of the quotes, since it the length of the string is provided. I have other sets of data, in which quotes and doublequotes appear, but they are no problem at all.

I will try to put together a list of parts according to your suggestion above and try to find the problem that way.
0
 
spiritwithinAuthor Commented:
Well, i was not able to figure out the error, and for the client it was more efficient to just redo the whole thing (it was a newsletter) based on the pieces of data i could provide him with. Therefore i can not seriously consider any answer to be the correct solution, so i will just choose any and provide you with the points. Thanks for trying to help.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now