Three ways to remove carriage return and line feed in PHP
- //php Line breaks in different systems
- //The implementation of line breaks in different systems is different
- //Use n in linux and unix
- //Use r in MAC
- //window for The difference from Linux is rn
- //So the implementation method is different on different platforms
- //php has three methods to solve
-
- //1. Use str_replace to replace newlines
- $str = str_replace(array("rn ", "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);
- ?>
Copy code
|