I have this, and want to add a new line after each entry, ...?
PHP Code:<?php
$val = $_GET['data'];
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $val;
fwrite($fh, $stringData);
fclose($fh);
?>
Printable View
I have this, and want to add a new line after each entry, ...?
PHP Code:<?php
$val = $_GET['data'];
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = $val;
fwrite($fh, $stringData);
fclose($fh);
?>
What does an entry look like? Ie: how would you know where to add a new line?
whoops sry, i meant after the,
I tried a few variations such as,PHP Code:fwrite($fh, $stringData);
andPHP Code:fwrite($fh, $stringData);
fwrite($fh, "\n");
andPHP Code:fwrite($fh, $stringData + "\n");
no joy though..PHP Code:fwrite($fh, "$stringData\n");
In HTML a line break is "<br />".
Still can't get this simple thing working, i am taking in a query string and printing it to a text file,
So the text file should look likePHP Code:<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$ref = $_GET['data'];
$newline = "<br />";
fwrite($fh,$ref.$newline);
fclose($fh);
?>
string1
string2
string3
but the above doesn't give that....
If your file is on a windows computer, you need to use "\r\n" for newlines, if it is on a mac then you should use just "\r".
Let me try this another way.
I want to append the incoming data to a text file, at the moment, the data is following on after each other on the same line with a newline character inbetween.
so if i send
.php?name= bill then
.php?name= john then
.php?name= fred
then i want that saved to a text file like
bill
john
fred
at the moment its saving as
bill john fred the spaces being newline characters.
Are you using Window or Linux, did you try \r\n.
Forget <br />, I thought you were trying to display newlines in an HTML document.