Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Am I losing my mind? (PHP strings)

    I have a variable that holds a string called $applications. The string is a serialized array.

    When I try and run unserialize($applications) on it is unsuccessull, HOWEVER when I write the value of $applications to an empty text file and run unserialize on the acutal value, it succeeds.

    i.e.

    1) unserialize($applications); // this fails

    2) unserialize('a:1:{i:0;a:4:{s:8:"Personal";b:1;s:2:"ID";s:5:"39593";s:7:"Surname";s:9:"Raithatha";s:9 :"Workflows";a:1:{i:0;a:3:{s:12:"WorkflowName";s:17:"Oversized Answers";s:6:"SeqNum";s:1:"4";s:9:"Questions";a:1:{i:0;a:5:{s:4:"Text";s:56:"Do you have demonstrated experience in software testing?";s:5:"WFQID";s:7:"2400728";s:6:"SeqNum";s:1:"1";s:6:"Answer";s:12:"12345
    67890";s:4:"File";s:1:"f";}}}}}}') // this succeeds

    Now, 2) IS the value produced from $applications. Further more, running a strcmp() on the two returns -1 (not equal). How is it possible that the variable and the outputed value that it holds be different??

    * Has this got something to do with new line characters??

    thanks in advance to anyone that can provide some info

  • #2
    Senior Coder
    Join Date
    Aug 2003
    Location
    One step ahead of you.
    Posts
    2,815
    Thanks
    0
    Thanked 3 Times in 3 Posts
    It's possible. You should check what's actually in the variable (with var_dump()) if the content really is there.
    I'm not sure if this was any help, but I hope it didn't make you stupider.

    Experience is something you get just after you really need it.
    PHP Installation Guide Feedback welcome.

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the promt reply, appreciate it. This is what is outputed from var_export($applications)

    // using var_export on $applications
    'a:1:{i:0;a:4:{s:8:"Personal";b:1;s:2:"ID";s:5:"39593";s:7:"Surname";s:9:"Raithatha";s:9:"Workflows" ;a:1:{i:0;a:3:{s:12:"WorkflowName";s:17:"Oversized Answers";s:6:"SeqNum";s:1:"4";s:9:"Questions";a:1:{i:0;a:5:{s:4:"Text";s:56:"Do you have demonstrated experience in software testing?";s:5:"WFQID";s:7:"2400728";s:6:"SeqNum";s:1:"1";s:6:"Answer";s:12:"12345
    67890";s:4:"File";s:1:"f";}}}}}}'

    If i unserialize the above string it works fine. but If I unserialize($applications) it fails. I really am lost on this one!

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Have you tried this?

    PHP Code:
    // ... create $applications variable ...
    $data serialize($applications);
    $applications unserialize($data); 
    If you try to unserialize right away you'll know whether the issue is with the variable contents. However I don't think unserialize/serialize has problems with that. It sounds like something else is wrong. Maybe if you give out more information about the situation, such as how the $applications variable is constructed, what is done with it before serializing, or unserializing, etc.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •