Page 1 of 1

Writing Certain Phrases To File Comes Out In Chinese?

Posted: Fri Jul 16, 2010 11:10 am
by jason.teagle
I'm using fopen(, "a") / flock() / fputs() / flock() / fclose() to write out a few small files. I'm writing out a line each time. The calling code passes in the string to write out, I add a \n, and that's it.

The four phrases I tried writing out were

Another element
Another format
Another liked genre
Another seeking genre

The first two never had a problem; the last two produced the Chinese characters!

The odd thing is, if I add the \n straight on to the end using

$Line . "\n"

or

"$Line\n"

it goes wrong; if I add at least one space first, then the \n, it works just fine.

I'm running PHP 4.4.7 on Apache 1.3.27 on my Windows 7 machine. (\n is just fine for a line ending here, I can read it in Notepad2 just fine).

Note that as per the PHP recommendation, I'm not using "t" on Windows but instead letting it use the exact line ending I specify.

Any idea what's causing this? The workaround will do for now, but I'd like to understand whay.

Re: Writing Certain Phrases To File Comes Out In Chinese?

Posted: Fri Jul 16, 2010 12:56 pm
by AbraCadaver
I assume you view this in notepad? \r\n is the Windows line ending, so when using just \n it is rendered strangely in notepad. Most other editors, Wordpad, Notepad++ don't have this problem. You can use another editor, or use the PHP_EOL constant instead of \n or just hardcode the \r\n if you expect it to be viewed in notepad.