Those files are giving me a headache. I have a simple form 2 fields and I want to write the content of those 2 fields to a file. Then on another page I want to display the content of the file.
Name:
Description:
$filename="files/new.txt";
if (isset ($_POST['name']) || isset ($_POST['desc']))
{
$name=trim($_POST['name']);
$desc=trim($_POST['desc']);
// get rid of enter
$name = str_replace("\n","",$name);
$desc = str_replace("\n","",$desc);
$data = trim($name."\n".$desc."\n");
//opening a file
$fp = fopen($filename, "w+") ;
//writing to a file
fwrite($fp, $data);
//closing a file
fclose($fp);
}
in another file I want to read those 2 fields in 2 seperate lines
$lines=file('files/new.txt');
for ($i=1;$i<count($lines);$i++)
{
echo $lines[$i] . "<br /><br />\n";
}
In the file new.txt everything is in 1 line. Why is it in 1 line if I use $data = trim($name."\n".$desc."\n");