AncientSage Posted July 21, 2006 Share Posted July 21, 2006 I have multiple arrays stored in a text file, they're serialized, so if I don't unserialize them, they come back in the serialized form. Anyway, I've unserialized them, and attempted to make it so they work, but now it's only returning one of the arrays in my foreach loop. As if it's only unserializing one array, and getting rid of the rest...Example...s:40:"text ";s:40:"text ";s:40:"text ";Now, it's only returning the first line, I need it to unserialize all 3 arrays, and display them all. Any ideas how that would be done? Do I need to use the explode function before or after I unserialize? Quote Link to comment https://forums.phpfreaks.com/topic/15285-before-unserialized-it-worked/ Share on other sites More sharing options...
AncientSage Posted July 21, 2006 Author Share Posted July 21, 2006 It's not displaying any now, here is the code...[code] $fp = fopen($textfile, "r"); $file = file_get_contents($textfile, False, NULL); $u_rows = unserialize($file); $rows = explode("\n", $u_rows); delete_row($rows); //Pay no attention to this, it doesn't effect the overall code. } echo "<form action=\"" . append_sid("admin.php") . "\" method=\"POST\">"; foreach($rows as $x => $row) { if($row == ""){ continue; } echo '<input type="checkbox" name="row[]" value="'. $x .'">' . $row . "<br /> "; } echo "<input type=\"hidden\" name=\"checksubmit\">"; echo "<br /><input type=\"submit\" value=\"Delete Selected\">"; echo "</form>"; [/code] Quote Link to comment https://forums.phpfreaks.com/topic/15285-before-unserialized-it-worked/#findComment-61828 Share on other sites More sharing options...
kenrbnsn Posted July 21, 2006 Share Posted July 21, 2006 You're doing the unserialize at the wrong time, try this:[code]<?php$fcontents = file($textfile); // read the entire file into an arrayforeach ($fcontents as $line) { $arr = unserialize($line); echo '<pre>' . print_r($arr, true) . '</pre>';}?>[/code]See if this works and then apply the concept to your script.Ken Quote Link to comment https://forums.phpfreaks.com/topic/15285-before-unserialized-it-worked/#findComment-61830 Share on other sites More sharing options...
AncientSage Posted July 21, 2006 Author Share Posted July 21, 2006 That's what I attempted earlier, I must've done something wrong though, as it didn't work last time I attempted. Anyway, thanks for the help, and it's working now after applying it to the code the way you posted. Quote Link to comment https://forums.phpfreaks.com/topic/15285-before-unserialized-it-worked/#findComment-61832 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.