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

Share: Three ways to remove carriage return and line feed in PHP

WBOY
WBOYOriginal
2016-07-25 08:57:381018browse
  1. //php line breaks in different systems
  2. //The implementation of line breaks is different between different systems
  3. ///n is used in linux and unix
  4. ///r is used in MAC // bbs.it-home.org
  5. //window In order to reflect the difference from Linux, it is /r/n
  6. //So the implementation methods are different on different platforms
  7. //php There are three ways to solve it
  8. //1. Use str_replace to replace newlines
  9. $str = str_replace(array("/r/n", "/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