Torsten Rosenberger wrote:
^M carachters in in

Classical pblm of representing "end of line" in text files between OS: windows uses \r\n aka CRNL *nix uses \n aka NL (newline) mac uses \r aka CR (carriage return)

Good text editors dont care (win: wordpad, not notepad) and can
convert while reading/writing (emacs, vim, etc). --not sur for mac way.
Use hex editor to know for sure what is 'the' newline char.
\r is 0D in hex
\n is 0A in hex

$ hexdump -C file.txt | head -20

In your case, the src file contains \r\n or the file is written
in text mode on a windows server, most probably.

$fp = fopen ("draft.html", "r");
$incont = fread ($fp,filesize("draft.html"));
(...)
$fp = fopen ("out.html","w");
fputs ($fp, $content);
the out put get ugly ^M

With files _in_text_mode_ (see flags of fopen), the "\n" char in PHP is "virtual" : following OS, PHP version, it can be written as \r, \r\n or \n. Either use non portable "t" flag on windows to make transparent \r\n -- \n translations, or better always use files in _binary_ mode and choose yourself your eol char (\n is simpler). The latter will improve portability. See php official doc

http://www.php.net/manual/en/function.fopen.php

FYI: Perl also use a 'virtual' \n char, and that can cause problems.
Most of Internet protocols use \r\n as line separators, and sending
only \n is asking for trouble soon or later... See perlport(1)

Specific info for vim:
:help dos-file-formats
vim -b file.txt (read in binary mode, eol is always \n)
:set ff=dos   (read any, write \r\n)
:set ff=unix  (read dos, write \n)

Not using emacs often enough to provide same info. Someone here ?
It also does right things automatically, but dont know
shortcuts or functions to alter that correct behavirou ;-)

Hope it helps,

Christophe

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to