tomhoad Posted October 9, 2009 Share Posted October 9, 2009 Hi there. I have some data in my database that is serialized. e.g. a:2:{i:0;s:9:"Test";i:1;s:4:"Another Test";} I'm unsure how to use unserialize to convert it into a string in the format: Test, Another Test Currently I have: $radio_array = unserialize($radio); foreach ($radio_array as $i => $value) { print($radio_array[$i]); } But that throws errors. Any help appreciated, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/ Share on other sites More sharing options...
lemmin Posted October 9, 2009 Share Posted October 9, 2009 How did you serialize that? "Test" is not a 9 character string (s:9) and "Another Test" is not a 4 character string (s:4). Try changing those to 4 and 12 respectively and it might work. Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-933855 Share on other sites More sharing options...
tomhoad Posted October 10, 2009 Author Share Posted October 10, 2009 Sorry I've replaced the serialized data as it's personal data! Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-934234 Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 at face value, there's nothing wrong with what you posted. It would help if you posted what error you got. Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-934283 Share on other sites More sharing options...
MadTechie Posted October 10, 2009 Share Posted October 10, 2009 Well your serialized value is wrong! as lemmin stated it should be a:2:{i:0;s:4:"Test";i:1;s:12:"Another Test";} and to get the result you don't need to do a loop try this echo implode(", ", unserialize($radio)); Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-934331 Share on other sites More sharing options...
.josh Posted October 10, 2009 Share Posted October 10, 2009 Well your serialized value is wrong! Sorry I've replaced the serialized data as it's personal data! Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-934334 Share on other sites More sharing options...
MadTechie Posted October 10, 2009 Share Posted October 10, 2009 oops missed that reply! Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-934341 Share on other sites More sharing options...
lemmin Posted October 12, 2009 Share Posted October 12, 2009 What is the error? I think you might be going about this troubleshooting wrong. Try the same thing with serialized data that is NOT personal - data that you can post here. I am guessing that the problem is either the inputs or not even in that part of your code. Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-935606 Share on other sites More sharing options...
Zane Posted October 12, 2009 Share Posted October 12, 2009 do a print($radio_array) as see what that gives you... and what error is it throwing exactly Quote Link to comment https://forums.phpfreaks.com/topic/177109-using-unserialize/#findComment-935608 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.