Take the 2-minute tour ×

I have the following serialized PHP array stored in a mySQL database:


Now, I managed to output that value with:

echo "$my_data";

but I can't manage to unserialize it. I tried this but it doesn't work:


When I add that in between, all I get is a blank page. Any ideas?

share|improve this question
Have you turned on display_errors? Or looked into your error logs. A blank screen often indicates some kind of error. –  liquorvicar Apr 1 '12 at 14:57
I just tried that and get this: Notice: unserialize() [function.unserialize]: Error at offset 12 of 62 bytes in test.php on line 25 –  user1227914 Apr 1 '12 at 15:08
Have you checked the string returned from the db is identical to the string you put into the db? btw it's not usually considered good practice to store a serialised string in a db. –  liquorvicar Apr 1 '12 at 15:13
and var_dump shows bool(false) –  user1227914 Apr 1 '12 at 15:14
Yeah, the string is the same. Unfortunately my software developer did it that way, not me :( I tested the serialized string on unserialize.net and it decoded it fine there, so I figure the problem must be on my end. –  user1227914 Apr 1 '12 at 15:15
add comment

1 Answer

up vote 3 down vote accepted

Maybe you should look at the process of inserting the the value into the database. Is it possible that after the values are serialized, that they were encoded in someway, such as to html entities or something?

I ran a test locally and I got the same error message. Here is output:

a:2:{i:2070;s:4:"0.00";i:1901;s:4:"1.00";} Notice: unserialize(): Error at offset 12 of 62 bytes in /srv/localhost/public_html/test.php on line 6 

Here is code


$value = htmlentities('a:2:{i:2070;s:4:"0.00";i:1901;s:4:"1.00";}');
echo $value;

share|improve this answer
that was the problem! The " was converted into HTML tags. I replaced them and now it works! –  user1227914 Apr 1 '12 at 19:25
add comment

Your Answer


