Home >Backend Development >PHP Tutorial >Three methods of removing line breaks in PHP
//php Line breaks in different systems
//The implementation of line breaks between different systems is different
///n is used in linux and unix
//MAC uses /r
//window In order to reflect the different rules from linux Yes /r/n
//So the implementation methods are different on different platforms
//There will be a lot of trouble in using the program you write to run on different platforms
//There are three ways to solve it in php
/ /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
Just follow the statement to be line-wrapped;
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, and under Linux, it will be / n, under mac it is /r
$str = str_replace(PHP_EOL, '', $str);