Hi there!
I'm trying to see if I'm capable of storing an array to a file and afterwards reading and displaying it. Judging from the results I'm not. 🙂 Here's what I've got so far:
<?php
$filename = "testfile.txt";
if(isset($name)){
$savestring = print_r($_POST,true);
$fd = fopen($filename, "w+")
or die("Can't open file $filename");
$write = fwrite($fd, $savestring);
fclose($fd);
}
$array = file($filename);
echo("<pre>");
print_r($array);
echo("</pre>");
echo("
<form name='test' method='POST' action='$php_self'>
Name:
<input type='text' name='name' value='".$array[name]."'>
Aftname:
<input type='text' name='aftname' value='".$array[aftname]."'>
<input type='submit'>
");
?>
What happens is that it stores my $_POST data into testfile.txt as follows:
Array
(
[name] => Hello
[aftname] => There!
)
It then converts this into an array, resulting in:
Array
(
[0] => Array
[1] => (
[2] => [name] => Hello
[3] => [aftname] => There!
[4] => )
)
Which is not what I meant to do, as I doesn't display the default values in my input text fields. So my question is: how would I do this right, so it actually displays the contents of my file in the text fields? Thanks!