Problem with new lines at the end while appending?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Problem with new lines at the end while appending?

Post by IceMetalPunk »

I have a PHP file hosted on a Windows server. Whenever I write a text file with it, the new line character writes fine. However, if I open a file for APPENDING and I try to add a new line to the begining with nothing before it, or to the end with nothing after it, it doesn't work. I need this because I'm using explode() to explode its contents at the line breaks. I know I could use a different character, but the line breaks make it much easier to read if I have to manually edit something. For example, if I open a file for appending only, and I write this to it: "\r\nHello" Hello appears, but there is no blank line above it. And if I type this: "Hello\r\n", there's no new line after Hello. But, if I do this: "Hello\r\nHi", then it works, and there IS a line between the 2 words.

Has this ever happened to anyone? If so, is there a way to fix it?

-IMP ;) :)

*EDIT* Of course, the blue are's are supposed to be the lower-case letter (*stupid filters*)
lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

windows prefers \r\n as a new line separator
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

Umm.... that's what I'm using.... It works fine when I have something before/after it, but not at the end or the beginning of the file....

-IMP ;) :)
Post Reply