Use of PHP linefeed and PHP_EOL variables

Source: Internet
Author: User
[Switch] use PHP to remove line breaks and PHP_EOL variables about n, r, t? N soft press enter :? In Windows, it indicates a line break and returns to the start position of the next line. in Linux and unix, it only indicates a line break, but does not return to the start position of the next line .? R soft space :? In Linux and unix, it indicates to return to the first position of the row .? In MacOS, the line feed is displayed and returned to the start position of the next line. this is equivalent to converting PHP to remove the use of line breaks and PHP_EOL variables.
About \ n, \ r, \ t?

\ N soft carriage return :? In Windows, it indicates a line break and returns to the start position of the next line. in Linux and unix, it only indicates a line break, but does not return to the start position of the next line .?

\ R soft space :? In Linux and unix, it indicates to return to the first position of the row .? In Mac OS, it indicates a line break and returns it to the start position of the next line, which is equivalent to \ n in Windows .?

\ T hop (move to the next column )?

What are the notes :?

  1. They are valid in double quotes or delimiters. they are invalid in single quotes .?
  2. \ R \ n is generally used together to represent the carriage return key (in Linux and Unix) on the keyboard. \ n (in Windwos) can also be used only, and \ r is used to represent the carriage return in Mac OS.
  3. \ T indicates the "TAB" key on the keyboard .?
  4. File line break: windows: \ n, linux, unix: \ r \ n
// Different php systems use different line breaks. // different systems use different lines. // for linux and unix, use/n // for MAC, and use/r // window to reflect differences from linux. it is/r/n // so the implementation methods are different on different platforms // php has three methods to solve the problem // 1. use str_replace to replace the line feed $ str = str_replace (array ("/r/n ", "/r", "/n"), "", $ str); // 2. use regular expressions to replace $ str = preg_replace ('// s */', '', $ str); // 3. use the variables defined in php (recommended) $ str = str_replace (PHP_EOL,'', $ str );

?

????? PHP_EOL (end of line) is a defined variable that represents the line break of php. this variable will change according to the platform. in windows, it will be/r/n, in linux, it is/n, and in mac, it is/r. line Feed is followed by the following line.

?

$str = str_replace(PHP_EOL, '', $str);

?

?

This article

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.