Summary of PHP methods removing newline characters (php_eol using variables)

Source: Internet
Author: User

A small package, in fact, different platforms have different implementations. Why are you doing this? It can be a world that is diverse.

Originally UNIX and the world had to replace it with/N, but windows in order to reflect their differences. To use/r/n, the more interesting thing is that Mac with/R. So UNIX series/n. Windows series with/r/n. Mac with/R, so you can write a program on different platforms to perform a lot of trouble. Here are some common ways to remove line breaks from PHP.

The first type of notation:




Another way to do this:

Str_replace ("\ r \ n", "", $str);

The third type of notation:


About \n,\r,\t
\ n Soft return: Represents a line break in Windows and returns to the start of the next line, in Linux, Unix, but not back to the start of the next line.


\ r Soft space: in Linux, Unix represents the return to the start of the line.

Represents a newline in Mac OS and returns to the start of the next line, equivalent to the effect of \ n in Windows.


\ t jump (move to next column)

A few notes:

They are valid in a string represented by a double-or delimiter, and are not valid in a string represented by a single-argument.
\ r \ n generally used together, to indicate the key on the keyboard return (Linux,unix), you can just use \ n (windwos), in Mac OS with \ r to indicate carriage returns.


\ t represents the "tab" key on the keyboard.
Line break symbol in file: Windows: \ n. Linux,unix: \ r \ n

Supplemental Code:

<?


Php_eol is a well-defined variable, representing the PHP newline character, which varies depending on the platform, is/r/n under Windows,/n under Linux, and/R under Mac. Line-up will be as follows.


Regular Replacement:





Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

Summary of PHP methods removing newline characters (php_eol using variables)

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.