Home >Backend Development >PHP Problem >How to remove carriage return in php
php method to remove carriage returns: 1. Use [str_replace] to replace newlines; 2. Use regular replacement; 3. Use variables defined by php, the code is [$str = str_replace(PHP_EOL, '' , $str)].
php method to remove carriage returns:
php Line breaks in different systems
Different systems The implementation of line breaks is different
Use in Linux and Unix \n
Use \r in MAC
In order to reflect the difference from linux, window is \r\n
So the implementation methods are different on different platforms
php There are three ways to solve it:
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)
$str = str_replace(PHP_EOL, '', $str);
If you want to know more about programming learning, please pay attention to the php training column!
The above is the detailed content of How to remove carriage return in php. For more information, please follow other related articles on the PHP Chinese website!