fopen () How to write a cross-system wrapping of file content how to do

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