Connecting Tech Pros Worldwide Forums | Help | Site Map

How to write string in a file to the next line

marslee@hotmail.com
Guest
 
Posts: n/a
#1: Jul 17 '05
How to write data in a file to the next line

fwrite($ourFileHandle , $_POST[user]);
fwrite($ourFileHandle , "\n");
fwrite($ourFileHandle , $_POST[address]);

I want the following output

Peter
Main.st

How can i do that?
I tried many time,but Peter and main.st are on the same line.


Janwillem Borleffs
Guest
 
Posts: n/a
#2: Jul 17 '05

re: How to write string in a file to the next line


marslee@hotmail.com wrote:[color=blue]
> How to write data in a file to the next line
>
> fwrite($ourFileHandle , $_POST[user]);
> fwrite($ourFileHandle , "\n");
> fwrite($ourFileHandle , $_POST[address]);
>
> I want the following output
>
> Peter
> Main.st
>
> How can i do that?
> I tried many time,but Peter and main.st are on the same line.
>[/color]

\n only shows up in your browser when enclosed with <pre> tags.

Look at the source directly, use <pre> tags or use <br> instead of \n



JW

Good Man
Guest
 
Posts: n/a
#3: Jul 17 '05

re: How to write string in a file to the next line


marslee@hotmail.com wrote in news:1115044776.207438.318080
@o13g2000cwo.googlegroups.com:
[color=blue]
> How to write data in a file to the next line
>
> fwrite($ourFileHandle , $_POST[user]);
> fwrite($ourFileHandle , "\n");
> fwrite($ourFileHandle , $_POST[address]);
>
> I want the following output
>
> Peter
> Main.st
>
> How can i do that?
> I tried many time,but Peter and main.st are on the same line.[/color]

$user = trim($_POST['user']);
$add = trim($_POST['address']);

fwrite($ourFileHandle, "$user\n$add");



Good Man
Guest
 
Posts: n/a
#4: Jul 17 '05

re: How to write string in a file to the next line


Good Man <heyho@letsgo.com> wrote in news:Xns964A75DAB70FEsonicyouth@
216.196.97.131:
[color=blue]
> marslee@hotmail.com wrote in news:1115044776.207438.318080
> @o13g2000cwo.googlegroups.com:
>[color=green]
>> How to write data in a file to the next line
>>
>> fwrite($ourFileHandle , $_POST[user]);
>> fwrite($ourFileHandle , "\n");
>> fwrite($ourFileHandle , $_POST[address]);
>>
>> I want the following output
>>
>> Peter
>> Main.st
>>
>> How can i do that?
>> I tried many time,but Peter and main.st are on the same line.[/color]
>
> $user = trim($_POST['user']);
> $add = trim($_POST['address']);
>
> fwrite($ourFileHandle, "$user\n$add");[/color]

(assuming you were writing to a text file)
Chung Leong
Guest
 
Posts: n/a
#5: Jul 17 '05

re: How to write string in a file to the next line


On Windows you need \r\n to produce a newline. Most editor is smart
enough to recognize \n, but not Notepad. You used to be able to open a
file in text mode, which turns on automatic translation of \n to \r\n.
But the PHP devs now are discouraging its use and, the last time I
tried, it didn't work.

Closed Thread