Home  >  Article  >  Backend Development  >  Three ways to remove carriage return and line feed in PHP

Three ways to remove carriage return and line feed in PHP

WBOY
WBOYOriginal
2016-07-25 08:48:31863browse
Three ways to remove carriage return and line feed in PHP
  1. //php Line breaks in different systems
  2. //The implementation of line breaks in different systems is different
  3. //Use n in linux and unix
  4. //Use r in MAC
  5. //window for The difference from Linux is rn
  6. //So the implementation method is different on different platforms
  7. //php has three methods to solve
  8. //1. Use str_replace to replace newlines
  9. $str = str_replace(array("rn ", "r", "n"), "", $str);
  10. //2. Use regular replacement
  11. $str = preg_replace('//s*/', '', $str);
  12. //3. Use variables defined by PHP (recommended)
  13. $str = str_replace(PHP_EOL, '', $str);
  14. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn