Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.