user2235005
user2235005

Reputation: 5

create Line break/new line after fwrite() PHP

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

Answers (1)

BlitZ
BlitZ

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

Related Questions