Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Here's an easy one

Status
Not open for further replies.

skiflyer

Programmer
Sep 24, 2002
2,213
US
I'm outputting to a text file... I need a newline at the end of my line..

I've tried..

fputs ("blah\n");
fputs ($variable."\n");
fputs ($variable.'\n');

and then all those with fwrite... no success... any advice?

I jess need a new line man! Never seen this problem... my lines I'm grabbing from a text file with the newline included are doing dandy when I rewrite them to the newfile.

IIS server, PHP 4.02.whatever, NT Box.

-Rob
 
Hi,

Use this:
Code:
<?php

$fp = fopen(&quot;text_file.txt&quot;, &quot;a&quot;);
fwrite($fp, &quot;blah\n$variable\n$variable2\n&quot;);

?>

You could also do a new fwrite for everything too if you want.

Hope this helps!
relax.gif

 
That's actually the same as what I've been doing...

reads fine in wordpad... emacs and notepad both have funny little boxes instead of the newline.

-Rob

Any other advice?
 
I've now additionally tried appending chr(12) & chr(13) to the end of my variables and gotten the same result.

I'm baffled, never run across this with PHP before, I'm assuming it has something to do with the way IIS4 and PHP are working together... the odd thing to me is that I also read in variables from a text file which have a newline on the end of them, and they write out with the newline in tact...

my workaround will simply be to load the variables into a text file and read them out... but that's cheap and alot more maintenance than I want, so I'm still looking for an answer.

-Rob
 
I had a similar problem where newline would sometimes work and othertimes not I couldn'tunderstand why, but I put the newline at the start instead of the end and it seems to work OK

Code:
fputs (&quot;\nblah&quot;);
fputs (&quot;\n&quot;$variable.);
fputs ('\n'$variable.);

Ian
 
&quot;\n&quot; is the Unix way of denoting a new line in a file.

&quot;\r\n&quot; is the DOS way of doing the same.

If the file uses &quot;\n&quot; as its newline designator, and the file is opened on a Win32 box, unless the editor is bright enough to recognize that &quot;\n&quot; is a possible line end sequence, you'll get weird stuff to the screen.

Notepad I expected to react badly. I'm suprised that emacs did, too.
Want the best answers? Ask the best questions: TANSTAAFL!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top