Jump to content

Archived

This topic is now archived and is closed to further replies.

AncientSage

Before unserialized it worked...

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
You're doing the unserialize at the wrong time, try this:
[code]<?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>';
}
?>[/code]

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

Ken

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.