Jump to content

Writing to file, new line character \n doesn't work


HughbertD

Recommended Posts

Hi all,

 

I am writing some data to a file (well appending)

 

I am using \n for a new line return, but all I get is a small square, and all the data is on one line

 

$file="export_$time";
$handle=fopen($file,'a');
$data="$start2 TO $end2\n";
fwrite($handle, $data);
fclose($handle);

 

Thanks for any help you can give.

If you open it in word or some rich text editor then save it, it will work.

 

It's just the way notepad is.

 

or a less im missing somthing on how to get past it...

 

Give \n\r a try but im sure it does the same.

 

Rgards

Liam

\r\n worked!

 

Thanks!

 

\n = windows systems

\r = unix

 

when you use both the version of OS you run ignores the other usually

 

Are you sure? From what I have found through experience, *nix is \n while windows is \r\n

Windows can accept either \r\n or \n as a new lines. It all depends on the application you use to view the generated file. Notepad prefers \r\n for newlines any other new line char and it'll display [] in replacement.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.