How does fopen () write the file content to the bottom of the line feed across the system? I am a newbie and want to use fopen () to write content to files. The following is a description on the php official website: ------------------------------------------------------- Note: different operating system families have different end habits. When you write a text file and want to insert a new row, you need to use the line terminator fopen () that complies with the operating system to write the file content. how can this problem be solved?
I am a newbie and want to use fopen () to write content to files.
The instructions on the php official website are as follows:
-----------------------------------------------------------
Note:
Different operating system families have different row termination habits. When you write a text file and want to insert a new row, you must use the line termination symbol that complies with the operating system. Unix-based systems use \ n as the row end character, Windows-based systems use \ r \ n as the row end character, and Macintosh-based systems use \ r as the row end character.
If an incorrect row end symbol is used when writing files, other applications may encounter a strange behavior when opening these files.
In Windows, a text conversion mark ('t') is provided to transparently convert \ n to \ r \ n. You can also use 'B' to force the binary mode to avoid data conversion. To use these tags, either 'B' or 'T' is used as the last character of the mode parameter.
The default conversion mode depends on SAPI and the PHP version used. therefore, to facilitate migration, you should always specify the appropriate tag. If a plain text file is operated and \ n is used as the row Terminator in the script, but it is expected that these files can be read by other applications such as Notepad, then, use 't' in the mode '. Use 'B' in all other cases '.
If the 'B' flag is not specified when operating the binary file, some strange problems may occur, including bad image files and strange problems about \ r \ n characters.
-----------------------------------------------------------
Note:
For portability considerations, we strongly recommend that you always use the 'B' flag when opening a file with fopen.
-----------------------------------------------------------
Note:
Again, for portability, we strongly recommend that you rewrite the code dependent on the 'T' mode to use the correct line terminator and change it to the 'B' mode.
-----------------------------------------------------------
The above are precautions on the official website.
[B] I don't know what mode should I use. since t mode is not recommended, windows notepad still cannot recognize line breaks in B mode... [/B]
Please advise!
------ 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