PHP writes a string to the txt file and returns a line break.-php Tutorial

Source: Internet
Author: User
PHP writes strings to the txt file, which causes line breaks.
$ DOCUMENTROOT = $ _ SERVER ['document _ root']; $ file = fopen ("$ DOCUMENTROOT/php_02/123.txt"," wb "); fwrite ($ file, "line 1 ". "\ n ". "line 2 n line 3"); fclose ($ file );

This is useless.
However
$ DOCUMENTROOT = $ _ SERVER ['document _ root']; $ file = fopen ("$ DOCUMENTROOT/php_02/123.txt"," wb "); fwrite ($ file, "line 1 ". "\ r \ n ". "line 2 n line 3"); fclose ($ file );

This is the case. ask why.


Reply to discussion (solution)

Different editors have different resolution effects.

Open the following two programs in the command line, and then use the program to open the generated file, you can see how the program parses \ n.
Notepad
Wordpad

In Windows, many editors wrap \ r \ n and ignore \ n.

You can enable the Word display control character function. \ n is the downward arrow and \ r \ n is the turning arrow.

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.