PHP writes a string to the TXT file, with a newline problem

Source: Internet
Author: User
$DOCUMENTROOT = $_server[' document_root ');    $file = fopen ("$DOCUMENTROOT/php_02/123.txt", "WB");    Fwrite ($file, "Line 1". " \ n "." Line 2 N line 3 ");    Fclose ($file);

It's useless.
But
$DOCUMENTROOT = $_server[' document_root ');    $file = fopen ("$DOCUMENTROOT/php_02/123.txt", "WB");    Fwrite ($file, "Line 1". " \ r \ n "." Line 2, Line 3 ");    Fclose ($file);

That's it, ask why.


Reply to discussion (solution)

Different editor parsing effect is different

Open the following two programs in the command line, and then open the generated file with the program, you can see how the program resolves \ n
Notepad
WordPad

Many editors in Windows put \ r \ nthe line, ignoring \ n

You turn the Word Display control character function on, \ n appears as a downward arrow, \ r \ n the arrow that appears as a corner

Window \ r \ n
Linux \ n

  • 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.