Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8897713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:25:02+00:00 2026-06-15T00:25:02+00:00

I have a file, serialized.txt, which contains a serialized array (created by doing serialize($array)).

  • 0

I have a file, “serialized.txt”, which contains a serialized array (created by doing serialize($array)).

s:133:"a:7:{i:0;i:640;i:1;i:480;i:2;i:2;i:3;s:24:"width="640" height="480"";s:4:"bits";i:8;s:8:"channels";i:3;s:4:"mime";s:10:"image/jpeg";}";

To fetch the contents I do:

$string = file_get_contents("serialized.txt");

Then I do:

print_r(unserialize($string));

The output that I get:

a:7:{i:0;i:640;i:1;i:480;i:2;i:2;i:3;s:24:"width="640" height="480"";s:4:"bits";i:8;s:8:"channels";i:3;s:4:"mime";s:10:"image/jpeg";}

This is the unserialized version of the string (contents of the file) when it should be printing the unserialized array. If I copy the string and do the following:

print_r(unserialize('a:7:{i:0;i:640;i:1;i:480;i:2;i:2;i:3;s:24:"width="640" height="480"";s:4:"bits";i:8;s:8:"channels";i:3;s:4:"mime";s:10:"image/jpeg";}'));

I get the correct output:

Array
(
    [0] => 640
    [1] => 480
    [2] => 2
    [3] => width="640" height="480"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

So the problem seems to be isolated to the serialized array when pulling from the file.

According to the unserialize docs the function should be returning false if there is a problem; not the contents of the string.

The serialized data is taken from getimagesize and I have verified that if I serialize another array and place it into the file:

serialize(array("hi"));

I can successfully generate the output:

Array
(
    [0] => hi
)

Are there any ideas why this may be happening? A bug with the serialization process relating to a getimagesize array, or potentially a “hidden” character in the file that my copy and paste removes? I have millions of these files already generated so it’s not possible for me to change the storage method. I guess the solution may just be to write my own parser to serialize the array? The input is always the same format so that’s plausible, but I would like to know of this a bug or my error with something somewhere.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T00:25:04+00:00Added an answer on June 15, 2026 at 12:25 am

    As far as I can see your data is double serialized so the following code should print your array:

    $string = file_get_contents("serialized.txt");
    print_r(unserialize(unserialize($string)));
    

    Although you should think about how you save to file. You may want to remove one serialization.

    Does that solve your problem?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which is serialized to and from an XML file when
I have a file that contains java serialized objects like Vector. I have stored
Let say I have a file that contains a serialized object by BinaryFomatter. Now
I have a serialized class of 30MB stored externally which contains lookup values. Each
I have a xml file, which is not serialized using XStream. It may be
I'm facing a problem to deserialize an XML file which have successfully been serialized
I have a bunch of multidimensional arrays serialized and saved in one txt file,
I have a file that contains serialized Java classes. I would like to parse
I have an XML file that I'm trying to serialize into an object. Some
I've the problem: I have to serialize class to XML file. But two properties

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.