...

View Full Version : Am I losing my mind? (PHP strings)



pludlow
01-24-2007, 07:37 AM
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 :o

marek_mar
01-24-2007, 07:57 AM
It's possible. You should check what's actually in the variable (with var_dump()) if the content really is there.

pludlow
01-24-2007, 08:36 AM
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!

aedrin
01-24-2007, 03:49 PM
Have you tried this?



// ... 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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum