|
-
Feb 10th, 2006, 02:22 AM
#1
Thread Starter
Frenzied Member
Best way to print a new line to a txt file ?
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);
?>
-
Feb 10th, 2006, 03:46 AM
#2
Re: Best way to print a new line to a txt file ?
What does an entry look like? Ie: how would you know where to add a new line?
-
Feb 10th, 2006, 04:00 AM
#3
Thread Starter
Frenzied Member
Re: Best way to print a new line to a txt file ?
whoops sry, i meant after the,
PHP Code:
fwrite($fh, $stringData);
I tried a few variations such as,
PHP Code:
fwrite($fh, $stringData);
fwrite($fh, "\n");
and
PHP Code:
fwrite($fh, $stringData + "\n");
and
PHP Code:
fwrite($fh, "$stringData\n");
no joy though..
-
Feb 10th, 2006, 04:03 AM
#4
Re: Best way to print a new line to a txt file ?
In HTML a line break is "<br />".
-
Feb 10th, 2006, 04:41 PM
#5
Thread Starter
Frenzied Member
Re: Best way to print a new line to a txt file ?
Still can't get this simple thing working, i am taking in a query string and printing it to a text file,
PHP 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);
?>
So the text file should look like
string1
string2
string3
but the above doesn't give that....
-
Feb 10th, 2006, 04:52 PM
#6
Re: Best way to print a new line to a txt file ?
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".
-
Feb 10th, 2006, 05:52 PM
#7
Thread Starter
Frenzied Member
Re: Best way to print a new line to a txt file ?
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.
-
Feb 10th, 2006, 06:31 PM
#8
Re: Best way to print a new line to a txt file ?
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|