Closed Thread Icon

Topic awaiting preservation: \n (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12187" title="Pages that link to Topic awaiting preservation: \n (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: \n <span class="small">(Page 1 of 1)</span>\

 
maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 04-21-2002 06:05

Don't you love my descriptive title? Anyways... I've never had this problem before, but writing \n to a file is really not working, see the code below:


$news = $Title . "\n" . $date . "\n" . $Message;
$file = fopen("news.txt","a");
fwrite($file,$news);
fclose($file);

the variables all work fine and everything, but everywhere in the file where there's supposed to be a newline because of the \n there is a weird little box thing. I don't know why it's doing this and I can't remember ever having this problem before. Can anyone help?

kewl

Mad Scientist

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-21-2002 06:25

Your title made me smile. =)

My *guess* about your problem: different operating systems treat newlines differently. Some use a carriage return character, some use a newline character, and some use both.

Perl treats "\n" as whatever the operating system that it's running on uses.

If you're running your perl script on one operating system (like on your server), and then opening the file in your native operating system (likely windows), and the file is being transferred as binary data (instead of ascii), then it's possible that your native operating system isn't understanding the server's operating system's newlines.

Just a guess.

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-21-2002 07:03

Maninacan, the newline *characters* are stored in the file, but some editors (I guess that you tried to open that file in Notepad) won't show line endings correctly when they use Unix line endings - only "\n" (on Windows you have to use "\r\n" instead). Don't worry about this, line ending are there and you can see them if you open that file in a modern HTML/text editor...

BTW Slime, Maninacan posted PHP code, not PERL...


maninacan
Paranoid (IV) Inmate

From: Seattle, WA, USA
Insane since: Oct 2001

posted posted 04-21-2002 07:43

Well, I don't think either of you are right. First off, Slime, the Server and the Client are both running the same OS, in fact they are the same machine, so I doubt that's the problem. And secondly Max, I opened it in Editplus which is a modern text/html editor, and it still didn't show them as newlines, and I know there's a way to do it without doing \r\n because I've done it before. Hmmm... What to do, What to do.

kewl

Mad Scientist

mr.maX
Maniac (V) Mad Scientist

From: Belgrade, Serbia
Insane since: Sep 2000

posted posted 04-21-2002 10:01

Try to open it in my HTML editor ( http://www.maxworld.co.yu/htmlbeauty/ )...


Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 04-22-2002 06:19

Perl and PHP look similar =)

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 04-22-2002 06:35

What OS are you running on?

And do you have a link to a sample file?
Actually they're both correct I bet the \n's are there.

You can always test this by reading the file and doing a \n search and replace





.:[ The Tao of Steve ]:.
Be Desireless
Be Excellent
Be Gone
...................................

« BackwardsOnwards »

Show Forum Drop Down Menu