0

THis this my code .

$data = array(
        '24 Jan|8:30' => '12.6',
        '22 Feb|8:30' => '250',
        '11 Mar|8:10' => '0',
        '31 Apr|23:30' => '7',
        '32 Apr|23:30' => '80',
        '33 Apr|23:30' => '67',
        '34 r|23:30' => '45',
        '35 Ap|23:30' => '66',
        '34 Lr|23:30' => '23',
        '3 Apr|23:30' => '23'
    );

    //echo serialize($data);
    $x = unserialize('a:10:{s:12:"24 Jan|8:30 ";s:4:"12.6";s:12:"22 Feb|8:30 ";s:3:"250";s:12:"11 Mar|8:10 ";s:1:"0";s:12:"31 Apr|23:30";s:1:"7";s:12:"32 Apr|23:30";s:2:"80";s:12:"33 Apr|23:30";s:2:"67";s:12:"34 r|23:30 ";s:2:"45";s:12:"35 Ap|23:30 ";s:2:"66";s:12:"34 Lr|23:30 ";s:2:"23";s:12:"3 Apr|23:30 ";s:2:"23";}');
    var_dump($x);

Not work in unserialize function. Please help!

1

3 Answers 3

4

The serialized representation of $data and the string you are trying to unserialize differ.

http://codepad.viper-7.com/3zlk1a

At offset 199 you see

s:12:"34 r|23:30 "

but the string (s) isn't 12 characters long (thats what s:12: mean). I guess something modified the serialized string directly. Just don't do it :) Always unserialize and work with the structured values.

Sign up to request clarification or add additional context in comments.

Comments

4
'a:10:{s:12:"24 Jan|8:30 ";s:4:"12.6";s:12:"22 Feb|8:30 ";s:3:"250";s:12:"11 Mar|8:10 ";s:1:"0";s:12:"31 Apr|23:30";s:1:"7";s:12:"32 Apr|23:30";s:2:"80";s:12:"33 Apr|23:30";s:2:"67";s:12:"34 r|23:30 ";s:2:"45";s:12:"35 Ap|23:30 ";s:2:"66";s:12:"34 Lr|23:30 ";s:2:"23";s:12:"3 Apr|23:30 ";s:2:"23";}'

...is not a valid serialization. Specifically, the s:12:"34 r|23:30 "; segment indicates that the string 34 r|23:30 contains 12 characters, which it does not.

Comments

-1
 $a = serialize($data);
 $x = unserialize($a);

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.