Originally in the UNIX world to replace the line with/n instead, but windows in order to reflect his differences, the use of/r/n, more interesting is in the Mac with/R. So the UNIX series with the/n,windows series with the/r/n,mac with/R, so that you write the program on different platforms run with a lot of trouble
A small line of change, in fact, different platforms have different implementations, why this, can be the world is diverse. Originally in the UNIX world to replace the line with/n instead, but windows in order to reflect his differences, the use of/r/n, more interesting is in the Mac with/R. So the UNIX series with the/n,windows series with the/r/n,mac with/R, so that you write the program on different platforms run with a lot of trouble. Here are some common ways to remove line breaks from PHP.
The first type of notation:
Copy CodeThe code is as follows: $content =str_replace ("\ n", "", $content);
Echo $content;
The second way:
Copy CodeThe code is as follows: Str_replace ("\ r \ n", "", $str);
The third type of notation:
Copy CodeThe code is as follows:
$content =preg_replace ("/\s/", "", $content);
Echo $content;
About \n,\r,\t
\ 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)
A few notes:
They are valid in a double-quote or delimiter-represented string, and are not valid in a single-quote string.
\ r \ n generally used together, to indicate the key on the keyboard return (Linux,unix), you can also only use \ n (windwos), in Mac OS with \ r to indicate carriage returns.
\ t represents the "tab" key on the keyboard.
NewLine symbol in file: Windows: \n,linux,unix: \ r \ n
Supplemental Code:
Copy CodeThe code is as follows:
<?php
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);
?>
Php_eol is a well-defined variable that represents the PHP newline character, which changes depending on the platform, is/r/n under Windows,/n under Linux, and/R under Mac. Line-up will be as follows.
Copy CodeThe code is as follows: $str = Str_replace (Php_eol, ", $STR);
PHP method Summary for removing line breaks (use of php_eol variables)