Home  >  Article  >  Backend Development  >  Summary of methods to remove line breaks in php

Summary of methods to remove line breaks in php

WBOY
WBOYOriginal
2016-07-25 09:05:48828browse
  1. $content=str_replace("n","",$content);
  2. echo $content;
Copy code

Method 2:

  1. str_replace("rn","",$str);
Copy code

Method 3:

  1. $content=preg_replace("/s/","",$content);
  2. echo $content;
Copy code

Attachment-----: n Soft return: In Windows, it means wrapping and returning to the beginning of the next line. In Linux and Unix, it only means line break, but it will not return to the beginning of the next line.

r Soft spaces: In Linux and Unix, it means returning to the beginning of the current line. In Mac OS, it means breaking a line and returning to the beginning of the next line, which is equivalent to the effect of n in Windows.

t Tab (move to next column)

A few notes: They are valid in strings represented by double quotes or delimiters, but not in strings represented by single quotes. rn is generally used together to represent the Enter key on the keyboard (in Linux and Unix). You can also just use n (in Windows). In Mac OS, use r to represent Enter! t represents the "TAB" key on the keyboard.

Newline symbols in files: windows : n linux,unix: rn

No matter how many theories there are, a simple example can make everyone understand more clearly:

  1. //php Line breaks in different systems

  2. //The implementation of line breaks in different systems is different
  3. //Linux and unix use /n
  4. // MAC uses /r
  5. //window to reflect the difference from Linux, which is /r/n
  6. //so the implementation methods are different on different platforms
  7. //php There are three methods to solve

  8. $str = str_replace(array("/r/n", "/r", "/n"), "", $str);

  9. < ;p>//2. Use regular replacement
  10. $str = preg_replace('//s*/', '', $str);

  11. //3. Use PHP to define it Variable (recommended)

  12. $str = str_replace(PHP_EOL, '', $str);
  13. ?>

Copy code

>>>> Articles you may be interested in: php remove string newline character instance analysis php compress html (clear newlines, clear tabs, remove comment marks) How to convert textarea line breaks in php forms Code examples of php regular filtering html tags, spaces, newlines, etc. How to compress html webpage code with php (remove spaces, newlines, tabs, comment marks, etc.) Provide several php methods to replace newline characters php generates excel and controls line breaks in Excel cells



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