- $content =str_replace ("\ n", "", $content);
- Echo $content;
Copy CodeMethod Two:
- Str_replace ("\ r \ n", "", $str);
Copy CodeMethod Three:
- $content =preg_replace ("/\s/", "", $content);
- Echo $content;
Copy CodeEnclosure-----: \ n Soft return: Represents a line break in Windows and returns to the beginning of the next line in Linux, Unix, but not back to the beginning of the next line. \ r Soft space: in Linux, Unix represents the return to the beginning of the line. Represents a newline in Mac OS and returns to the beginning of the next line, equivalent to the effect of \ n in Windows. \ t jump (move to next column) Note: They are valid in a string that is represented by double quotation marks or delimiters, and are not valid in a single quoted string. \ r \ n generally used together, used to indicate the key on the keyboard return (Linux,unix), can also be used only \ n (windwos), in Mac OS with \ r to indicate enter! \ t represents the "tab" key on the keyboard. NewLine symbol in file: Windows: \nlinux,unix: \ r \ n No more theory, a simple example, can let everyone see more clearly:
PHP line breaks for different systems
- The implementation of line breaks between different systems is not the same
- Linux and Unix with/n
- MAC with/R
- Window is/r/n in order to show that it is different from Linux
- So the implementation method on different platforms is not the same
- PHP has three ways to solve
1. Use Str_replace to replace line breaks
- $str = Str_replace (Array ("/r/n", "/R", "/n"), "", $str);
2. Use regular replacement
- $str = preg_replace ('//s*/', ' ', $str);
3. Use PHP-defined variables (recommended)
- $str = Str_replace (Php_eol, ", $STR);
- ?>
Copy Code>>> You may be interested in the article:php stripped string newline instance parsing php compressed HTML (clear line breaks, clear tabs, remove comment marks) PHP form to convert textarea line breaks PHP regular filter HTML tags , spaces, line breaks, and other code examples PHP compresses HTML page code (clear spaces, line breaks, tabs, comment markers, and so on) to provide several ways to replace line breaks in PHP PHP generates Excel and controls line breaks in Excel cells |