Jump to content

Before unserialized it worked...


AncientSage

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.