How to implement cross-system line feed of fopen () file content?

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.