Reputation: 5
Hello I am trying to write a php file that edits a text file. However I have a set of variables that each come from separate html form inputs. I want each of those values to display on a new line. I tried using PHP_EOL, "\n", and "\r\n". Below is my code. I hope someone may give me guidance. Note that everything works smoothly, except inserting a new line
<?php
$file="file.txt";
$fh=fopen($file , "a+");
$input1=$_POST['input1'];
$input2=$_POST['input2'];
$input3=$_POST['input3'];
fwrite($fh , $input1. " " . $input2 . " " . $input3 . "\n");
?>
Upvotes: 0
Views: 323
Reputation: 12168
Try replace:
fwrite($fh , $input1. " " . $input2 . " " . $input3 . "\n");
With:
fwrite($fh , $input1 . PHP_EOL . $input2 . PHP_EOL . $input3 . PHP_EOL);
As for me, it's working.
Upvotes: 1