Jump to content

php unserialize adding brackets around array keys?


ballhogjoni

Recommended Posts

the code is simple but the output is wrong.

 

$str = <<<EOF
a:2:{s:7:"visible";a:7:{i:0;s:5:"email";i:1;s:5:"print";i:2;s:8:"facebook";i:3;s:4:"digg";i:4;s:11:"stumbleupon";i:5;s:7:"twitter";i:6;s:6:"reddit";}s:6:"hidden";a:0:{}}
EOF;
echo "<textarea rows='10' cols='90'>";print_r(unserialize($str));echo "</textarea>";

 

the ouput is

Array
(
    [visible] => Array
        (
            [0] => email
            [1] => print
            [2] => facebook
            [3] => digg
            [4] => stumbleupon
            [5] => twitter
            [6] => reddit
        )

    [hidden] => Array
        (
        )

)

 

This is wrong I need something like this:

array (
  'visible' => 
  array (
    0 => 'email',
    1 => 'print',
    2 => 'facebook',
    3 => 'digg',
    4 => 'stumbleupon',
    5 => 'twitter',
    6 => 'reddit',
  ),
  'hidden' => 
  array (
  ),
)

 

What am I doing wrong? How do I fix it?

ok...I am trying to copy the output from the browser, but it doesn't work because of the brackets plus the browser parses the strings without the quotes. How can I do this? Basically I want to serialize it after i've made my changes to the unserialized array.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.