How can I convert this WordPress JSON entry into PHP array?

邮差的信 提交于 2019-12-25 17:07:45

问题


I am working on an interface to load data from a WordPress application into my own database. One table record comes with this:

a:6:{i:0;s:2:"39";i:1;s:2:"88";i:2;s:2:"89";i:3;s:2:"53";i:4;s:2:"54";i:5;s:2:"91";}

I know what this is representing and I think its a kind of JSON format, but I don't know how to convert this string into a readable PHP array.

I´ve tried to explode() something like explode(';'), but the result doesn't make any sense.

Have anyone seen this and can help me? Thanks.


回答1:


That's not a JSON string. It's a serialized array.

To make the serialized string into a regular array again, use unserialize:

$serialized_array = 'a:6:{i:0;s:2:"39";i:1;s:2:"88";i:2;s:2:"89";i:3;s:2:"53";i:4;s:2:"54";i:5;s:2:"91";}';
$unserialized_array = unserialize($serialized_array);

var_dump( $unserialized_array );


来源:https://stackoverflow.com/questions/56581702/how-can-i-convert-this-wordpress-json-entry-into-php-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!