Jump to content


Photo

Before unserialized it worked...


  • Please log in to reply
3 replies to this topic

#1 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 21 July 2006 - 07:09 PM

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?

#2 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 21 July 2006 - 08:12 PM

It's not displaying any now, here is the 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>";       


#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 21 July 2006 - 08:26 PM

You're doing the unserialize at the wrong time, try this:
<?php
$fcontents = file($textfile); // read the entire file into an array
foreach ($fcontents as $line) {
     $arr = unserialize($line);
     echo '<pre>' . print_r($arr, true) . '</pre>';
}
?>

See if this works and then apply the concept to your script.

Ken

#4 AncientSage

AncientSage
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 21 July 2006 - 08:38 PM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users