简体   繁体   中英

unserializing data array with php from mysql database

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

a:2:{i:2070;s:4:"0.00";i:1901;s:4:"1.00";}

Now, I managed to output that value with:

$my_data=mysql_result($result,$i,"my_data");
echo "$my_data";

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

$my_data=unserialize($my_data);

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

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

<?php

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

unserialize($value);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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