From ed0cbff43c790d0a02cbc81775fdee6443b986c1 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 7 Jun 2003 14:12:51 +0000 Subject: [PATCH] Explain a bit more about the nightmare that is the text-mode-translation, the spawn of satan. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@130532 c90b9560-bf6c-de11-be94-00142212c4b1 --- reference/filesystem/functions/fopen.xml | 60 +++++++++++++++++++----- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/reference/filesystem/functions/fopen.xml b/reference/filesystem/functions/fopen.xml index 3a140ff22a..b00618c4f9 100644 --- a/reference/filesystem/functions/fopen.xml +++ b/reference/filesystem/functions/fopen.xml @@ -1,5 +1,5 @@ - + @@ -122,25 +122,61 @@ - On systems that differentiate between binary ('b') and text ('t') mode - translation (such as Windows), the mode may contain - either the letter 'b' or the letter 't' as the last character to force - the translation mode to be either binary or text mode respectively. + Different operating system families have different line-ending + conventions. When you write a text file and want to insert a line + break, you need to use the correct line-ending character(s) for your + operating system. Unix based systems use \n as the + line ending character, Windows based systems use \r\n + as the line ending characters and Macintosh based systems use + \r as the the line ending character. - The default translation mode depends on the SAPI that you are using, so - you are encouraged to always specify the appropriate flag; you will - usually always want to specify 'b' if you intend for your script to be - portable between different platforms. + If you use the wrong line ending characters when writing your files, you + might find that other applications that open those files will "look + funny". + + + Windows offers a text-mode translation flag ('t') + which will transparently translate \n to + \r\n when working with the file. In contrast, you + can also use 'b' to force binary mode, which will not + translate your data. To use these flags, specify either + 'b' or 't' as the last character + of the mode parameter. + + + The default translation mode depends on the SAPI and version of PHP that + you are using, so you are encouraged to always specify the appropriate + flag for portability reasons. You should use the 't' + mode if you are working with plain-text files and you use + \n to delimit your line endings in your script, but + expect your files to be readable with applications such as notepad. You + should use the 'b' in all other cases. If you do not specify the 'b' flag when working with binary files, you - will experience strange problems with your data, including broken image + may experience strange problems with your data, including broken image files and strange problems with \r\n characters. - It is strongly recommended that you always use the 'b' flag - when opening files with fopen. + For portability, it is strongly recommended that you always + use the 'b' flag when opening files with fopen. + + + + Again, for portability, it is also strongly recommended that + you re-write code that uses or relies upon the 't' + mode so that it uses the correct line endings and + 'b' mode instead. + + + + As of PHP 4.3.2, the default mode is set to binary for all + platforms that distinguish between binary and text mode. If you are + having problems with your scripts after upgrading, try using the + 't' flag as a workaround until you have made your + script more portable as mentioned above. +