PHP Passing Serialized Array from Form to same Page
<p>I have the following script to update a text file containing six lines of text, each line with a date and content.  I am trying to allow the user to edit the text via an HTML form and the form pass that information back to itself for modifying the text file.  That part is not in there yet, but I'll deal with it later.</p>

<p>My problem is unserializing the array after it's posted.  Any help would be greatly appreciated.</p>

<pre><code>&lt;?php

$fp = fopen(dirname(__FILE__).'/scroller/db.txt','r+');
if (!$fp) {echo 'ERROR: Unable to open file.'; exit;}

if (isset($_REQUEST['serializedArray'])) {
    $serialized = $_REQUEST['serializedArray'];
    $unserialized = unserialize(stripslashes($serialized));
    print_r($unserialized);
    // Future code to modify db.txt file and save it.
}

$index = 0;
echo '&lt;form action="'.$_SERVER['PHP_SELF'].'" method="POST"&gt;&lt;table&gt;';
while (!feof($fp)) {
    $index++;
    $line = fgets($fp, 256); //Length of data per line to grab in db.txt file.
    $field[$index] = explode ('|', $line); // Column 0 = Date, 1 = Content.
    echo '
        &lt;tr&gt;
            &lt;td&gt;&lt;input type="text" name="date" size="20" value="'.$field[$index][0].'"&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="text" name="content" size="20" value="'.$field[$index][1].'"&gt;&lt;/td&gt;
        &lt;/tr&gt;';
    $fp++;
}
echo '&lt;/table&gt;';
$serializedArray = serialize($field);
fclose($fp);
echo "&lt;input type='hidden' name='serializedArray' value='".$serializedArray."'&gt;";
echo '&lt;input type="submit" value="Submit"&gt;&lt;/form&gt;';
?&gt;
</code></pre>

<p>Would this be easier using forms with sessions?</p>
