Re: fwrite and line breaks

From: Date: Fri, 13 Dec 2002 07:44:19 +0000
Subject: Re: fwrite and line breaks
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-128129@lists.php.net to get a copy of this message
On Fri, Dec 13, 2002 at 12:44:14AM -0600, Jami wrote: > > I know that fwrite needs to be written as such: > > $Open=fopen($MyFile, "w"); > fwrite($Open, "Text to add to file.\n"); > > The file is being saved on a Unix server, but Windows/Mac users will be downloading the file. > How can I create line breaks that notepad/textpad will use to create new lines, instead of boxes > where the break should be? I have tried changing "w" to "wb" as suggested on > php.net, but that does not work either and I am out of ideas. For Windows, use: fwrite($Open, "Text to add to file.\r\n"); And for Mac, I think it's: fwrite($Open, "Text to add to file.\r"); Aren't standards wonderful? ;-) If you want a more general solution, you might play with something like: $text="This is the first line.\nAnother line makes two.\n"; if ($target=="win") $text=str_replace( "\n", "\r\n", $text); else if ($target=="mac") $text=str_replace( "\n", "\r", $text); fwrite($Open, $text); Set your $target somewhere (maybe by parsing HTTP_USER_AGENT), and you can stick with consistent use of UNIX-style text in your PHP. There's probably a more elegant way to do this, but I don't know it. -- Paul Chvostek <paul@it.ca> Operations / Abuse / Whatever +1 416 598-0000 it.canada - hosting and development http://www.it.ca/

« previous php.general (#128129) next »