Question 1: How can I get a PHP script to output the carriage return (i.e. "\r") and/or the carriage return\newline (i.e. "\r\n") characters in my browser window?
I need to visually see whether a text file that I upload to my server hosting has lines that end with a carriage return ("\r") or a carriage return and a new line ("\r\n").
I want to output the actual backslash(es) \ and letters n and/or r in the browser window where I can visually see them. Is there a PHP built-in function that will do that?
Question 2a: What does the PHP Manual mean by "text-mode translation flag?"
The PHP Manual has confusing information in the description for the fopen() function.
It says that you should use the text-mode translation flag ('t') when working with plain text files. But below that it says that you should rewrite code that relies upon the 't' mode so that it uses the correct line endings.
Question 2b: The list of modes "A list of possible modes for fopen() using mode" shown on the page does not offer the 't' mode. How do you incorporate the 't' mode into your script if the 't' mode is not offered with the fopen() function?
I would appreciate if someone would help me clarify the issue with the r's, n's, and t's?
From the PHP Manual:
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.
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.