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.
Writing Certain Phrases To File Comes Out In Chinese?
Moderator: General Moderators
-
jason.teagle
- Forum Newbie
- Posts: 1
- Joined: Fri Jul 16, 2010 11:03 am
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Writing Certain Phrases To File Comes Out In Chinese?
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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.