fopen () How to write a cross-system wrap for a file content?
I'm a novice and want to write content to a file with fopen ().
Here is the instructions on the PHP official website:
-----------------------------------------------------------
Note:
Different operating system families have different end-of-line habits. When you write a text file and want to insert a new row, you need to use the line ending symbol that matches the operating system. Unix-based systems use \ n as the line-ending character, and the Windows-based system uses \ r \ n as the line-ending character, and the Macintosh-based system uses \ r as the line-ending character.
If you write to a file with an incorrect line-ending symbol, other applications may behave strangely when they open the file.
A text conversion token (' t ') is provided under Windows to transparently convert \ n to \ r \ n. With this counterpart, you can also use ' B ' to force binary mode so that the data is not converted. To use these tags, either use ' B ' or ' t ' as the last character of the mode parameter.
The default conversion mode relies on SAPI and the PHP version used, so it is always necessary to specify the appropriate markup for ease of porting. If you are manipulating plain text files and using \ n as the line terminator in the script, but also expect that these files can be read by other applications such as Notepad, use ' t ' in mode. Use ' B ' in all other cases.
If you do not specify a ' B ' tag when working with binaries, you may encounter some strange problems, including broken picture files and strange questions about \ r \ n characters.
-----------------------------------------------------------
Note:
For portability, it is strongly recommended that you always use the ' B ' tag when opening a file with fopen ().
-----------------------------------------------------------
Note:
Again, for portability reasons, it is strongly recommended that you rewrite code that relies on the ' t ' pattern to use the correct line terminator and change it to ' B ' mode.
-----------------------------------------------------------
The above is the official online attention.
[b] I do not understand, the bottom should use what mode, since not recommended with T mode, but B mode, Windows Notepad still can't recognize the line to ... [/b]
Please expert advice!
------Solution--------------------
PHP code
$file = fopen ("Test.txt", "WB"), Echo fwrite ($file, " Hello World. Testing!\r\nit is name is FFFF "); fclose ($file);
------Solution--------------------
Php_eol