开发者

Deserialize PHP array in coldfusion

I'm working on a Coldfusion project where I need to pull some information from a wordpress powered database. Some of the information that I need is in a serialized array stored in the wp_options table. I can't figure out how to deserialize the array data in Coldfusion.

I'm currently using the dev version of Coldfusion 8. I can't upgrade to Coldfusion 9 since my works application is build on Coldfusion 8

I've only been able to find this link http://www.cfinsider.com/index.cfm/2010/5/4/Serializing--Deserializing-in-ColdFusion-9 which talks about deserializing CFC's but it doesn't seem to work on the array I'm passing.

Here is an example of the data I'm trying to deserialze

a:2:{i:2;a:2:{s:5:"title";s:0:"";s:6:"number";i:5;}s:1开发者_开发百科2:"_multiwidget";i:1;}

Any help would be great.


Your best bet might be to check out Sean Corfield's scripting for ColdFusion project. I was able to do the following with it:

<script:php>
    <?php
        $array = unserialize('a:2:{i:2;a:2:{s:5:"title";s:0:"";s:6:"number";i:5;}s:12:"_multiwidget";i:1;}');
        $_COLDFUSION["test"] = json_encode($array);
    ?>
</script:php>

<cfdump var="#deserializeJSON(variables.test)#">

Which produced:

Deserialize PHP array in coldfusion


If you can serialize the PHP array into a JSON string, you can use deserializeJson on the CF side.


Well, that's a result of PHP serialization - I assume CF uses a completely different process. The schema seems pretty straightforward:

datatype:size:structure

or

numbertype:numbervalue

so

a:2:{i:2;s:3:"foo"}

would mean "array of size 2 { integer 2 ; string 'foo' of size 3 }". Note that arrays can be nested, and things can get complicated with Objects and other serialized classes (see PHP's manual on serializing objects).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜