- $ Content = str_replace ("\ n", "", $ content );
- Echo $ content;
Method 2:
- Str_replace ("\ r \ n", "", $ str );
Method 3:
- $ Content = preg_replace ("/\ s/", "", $ content );
- Echo $ content;
Appendix -----: \ 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 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) Note: they are valid in double quotation marks 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: \ nlinux, unix: \ r \ n There are more theories than a simple example, which can help you better understand:
// 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 );
- ?>
>>> Articles you may be interested in: php removes the string line break instance parsing php compresses html (clear line breaks, clear tabs, remove comment tags) php form conversion textarea linefeed method php regular filter html tags, spaces, linefeeds, and other code examples php compress html web code (clear spaces, linefeeds, tabs, comment tags, etc) methods to provide several php replacement of line breaks php to generate excel and control the line breaks in Excel cells |