2

I have serialized data and I am using PHP unserialize function which is not working for me. I do not know what is wrong with this string. This is how my serialized data look like. My PHP knowledge is limited so I could not figure out the issue in this data. Can any one help me with this.

s:73:"a:5:{i:0;s:4:"8941";i:1;s:4:"8939";i:2;s:4:"8942";i:3;s:4:"8946";i:4;s:4:"8950";}";
1
  • @Remy I replaced 2 with 4. Can you tell me what else is wrong in this string ? Commented Aug 4, 2021 at 18:16

1 Answer 1

2

You have a serialized string that contains a serialized array. The string length is 81 not 73.

s:81:"characters in between the first and last quotes and in the example there are 81"

$string = 's:81:"a:5:{i:0;s:4:"8941";i:1;s:4:"8939";i:2;s:4:"8942";i:3;s:4:"8946";i:4;s:4:"8950";}";';
$result = unserialize($string);

Yields the serialized array:

a:5:{i:0;s:4:"8941";i:1;s:4:"8939";i:2;s:4:"8942";i:3;s:4:"8946";i:4;s:4:"8950";}

Unserialize that:

$array = unserialize($result);

Yields the array:

Array
(
    [0] => 8941
    [1] => 8939
    [2] => 8942
    [3] => 8946
    [4] => 8950
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your answer and time. What are the meaning of s here. How you calculated its value which is 81

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.