0

I've never worked with serialized data... I need a little help with how to load "text" widgets title and content in php script outside wordpress...

my script just connects to database (including wp-config and using its values). secont thing is to load wp_options entries with option name sidebars_widgets and widget_text.

Here is where I do not know how to continue - data is serialized (example follows) and I don't know, how to process it in php...

widget_text content:
a:7:{
i:2;a:3:{s:5:"title";s:11:"lorem ipsum";s:4:"text";s:17:"...lorem ipsum...";s:6:"filter";b:1;}
i:3;a:3:{s:5:"title";s:0:"";s:4:"text";s:3:"...";s:6:"filter";b:0;}
i:4;a:3:{s:5:"title";s:0:"";s:4:"text";s:3:"...";s:6:"filter";b:0;}
i:5;a:3:{s:5:"title";s:0:"";s:4:"text";s:3;"...";s:6:"filter";b:0;}
i:6;a:3:{s:5:"title";s:7:"1234567";s:4:"text";s:0:"";s:6:"filter";b:0;}
i:7;a:3:{s:5:"title";s:7:"1234567";s:4:"text";s:0:"";s:6:"filter";b:0;}
s:12:"_multiwidget";i:1;}

Thanks for help

1 Answer 1

1

Use PHP's unserialize function:

<?php
$data = 'a:2:{i:0;s:12:"Sample array";i:1;a:2:{i:0;s:5:"Apple";i:1;s:6:"Orange";}}';
$unserialized = unserialize($data);

echo '<pre>';
print_r($unserialized);
echo '</pre>';
?>

Result:

Array
(
    [0] => Sample array
    [1] => Array
        (
            [0] => Apple
            [1] => Orange
        )
)

Got the sample data over at unserialize.com, a handy little site if you want to quickly check what's inside that serialized string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.