In the unix world, the newline is replaced by n, but in windows, rn is used to reflect its differences, and r is more interesting in mac. Therefore, unix series use n, windows series use rn, and mac use r. Therefore, using the program you write to run on different platforms has a lot of trouble with a small line feed, in fact, there are different implementations on different platforms. why is this possible? the world is diverse. Originally, the line feed in the unix world was replaced by/n, but in order to reflect its differences, windows uses/r/n. What's more interesting is that/r is used in mac. Therefore, unix/n, windows/r/n, and mac/r are used to run programs on different platforms. Below are some common methods for removing line breaks in PHP.
Method 1:
The code is as follows:
$ Content = str_replace ("\ n", "", $ content );
Echo $ content;
Method 2:
The code is as follows:
Str_replace ("\ r \ n", "", $ str );
Method 3:
The code is as follows:
$ Content = preg_replace ("/\ s/", "", $ content );
Echo $ content;
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 initial 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.
File line break: windows: \ n, linux, unix: \ r \ n
Additional 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 );
?>
PHP_EOL is a defined variable that represents the php line break. this variable will change according to the platform. in windows, it will be/r/n, and in linux it will be/n, under mac is/r. line Feed is followed by the following line.
The code is as follows:
$ Str = str_replace (PHP_EOL, '', $ str );