AncientSage Posted July 21, 2006 Share Posted July 21, 2006 I'm serializing the array, and all, but it's writing it back to the text file as "Array".[code] $textfile = "filelist.txt"; if (file_exists($textfile) && is_file($textfile)) { $fp = fopen($textfile, "r"); $file = file_get_contents($textfile, False, NULL); $rows = explode("\n", $file); if(isset($_POST['checksubmit'])) { if(isset($_POST['row'])) foreach($_POST['row'] as $i) unset($rows[$i]); serialize($rows); $fpw = fopen($textfile, "w"); flock($fpw, LOCK_EX); fwrite($fpw, $rows); flock($fpw, LOCK_UN); } } 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]Now, as you can see, I'm using explode() on part of the array, not sure it that could cause part of the problem. Anyway, what is wrong in this code that would be causing the array to keep writing back as Array? Quote Link to comment https://forums.phpfreaks.com/topic/15224-array-not-writing-to-file-as-expected/ Share on other sites More sharing options...
akitchin Posted July 21, 2006 Share Posted July 21, 2006 i have a feeling that it's because you're not returning the serial to anything. serialize() doesn't work directly on the variable, it returns the serialized version. try this:[code]$serialized_array = serialize($rows);...fwrite($fpw, $serialized_array);[/code]haven't used serialize before, so this is a guess. Quote Link to comment https://forums.phpfreaks.com/topic/15224-array-not-writing-to-file-as-expected/#findComment-61522 Share on other sites More sharing options...
AncientSage Posted July 21, 2006 Author Share Posted July 21, 2006 +1 rule of PHP I did not know (or more so, of the serialize() function). I guess that would be my problem then, as it is storing it as it should now. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/15224-array-not-writing-to-file-as-expected/#findComment-61523 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.