Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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