Home > Article > Backend Development > Three ways to remove line breaks in PHP
//php Line breaks in different systems
//The implementation of line breaks is different between different systems
///n is used in linux and unix
//MAC uses /r
//window In order to reflect the Linux is different /r/n
//So the implementation methods are different on different platforms
//It will be a lot of trouble to use the program you write to run on different platforms
//There are three ways to do PHP Solution
//1. Use str_replace to replace newlines
$str = str_replace(array("/r/n", "/r", "/n"), "", $str);
//2. Use Regular replacement
$str = preg_replace('//s*/', '', $str);
//3. Use variables defined by php (recommended)
PHP_EOL
Directly following the statement to be wrapped. Yes;
Here we have to re-look at the variables that have been defined in PHP
PHP_EOL is one of them, representing the newline character of PHP. This variable will change according to the platform. Under Windows, it will be /r/n, under Linux It is /n, under mac it is /r
$str = str_replace(PHP_EOL, '', $str);
The above introduces the codes of three methods of removing newlines in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.