Three ways to remove carriage return and line feed in PHP

WBOY
Release: 2016-07-25 08:48:31
Original
930 people have browsed it
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


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template