Summary of solutions for removing line breaks in PHP (PHP_EOL ). First writing method: $ contentstr_replace (n, $ content); echo $ content; second writing method: str_replace (rn, $ str); third writing method: $ contentpreg_replace (s, $ content); ec
Method 1:
$ Content = str_replace ("\ n", "", $ content );
Echo $ content;
Method 2:
Str_replace ("\ r \ n", "", $ str );
Method 3:
$ Content = preg_replace ("/\ s/", "", $ content );
Echo $ content;
Appendix:
First, let's talk about \ n, \ r, \ t
\ N soft carriage return:
In Windows, line breaks are displayed and returned to the beginning of the next line.
In Linux and unix, it only indicates line breaks, but does not return to the starting position of the next line.
\ R soft space:
In Linux and unix, return to the starting position of the row.
In Mac OS, line breaks are displayed and returned to the start position of the next line, which is equivalent to \ n in Windows.
\ T hop (move to the next column)
Notes:
They are valid in double quotes or delimiters, and are invalid in single quotes.
\ 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!
\ T indicates the "TAB" key on the keyboard.
Line Feed characters in the file:
Windows: \ n
Linux, unix: \ r \ n
Instance code:
The code is as follows:
// Line feed for different php systems
// The implementation of line feed varies with systems.
// In linux and unix/n
// For MAC/r
// Window is/r/n to reflect differences from linux
// The Implementation methods on different platforms are different.
// Php has three solutions
// 1. use str_replace to replace the line feed.
$ Str = str_replace (array ("/r/n", "/r", "/n"), "", $ str );
// 2. use regular expression replacement
$ Str = preg_replace ('// s */', '', $ str );
// 3. use the variables defined in php (recommended)
$ Str = str_replace (PHP_EOL, '', $ str );
?>
Response $ content = str_replace ("\ n", "", $ content); echo $ content; Method 2: str_replace ("\ r \ n ","", $ str); Method 3: $ content = preg_replace ("/\ s/", "", $ content); ec...