Home >Backend Development >PHP Tutorial >PHP remove string newline character example sharing_PHP tutorial
First way of writing:
The second way of writing:
The third way of writing:
Related explanations below:
First let’s talk about n, r, t
n soft carriage return:
means line break in Windows and returns to the beginning of the next line
in Linux/ In unix, it only means line break, but it will not return to the beginning of the next line.
r Soft space:
means return to the beginning of the current line in Linux/unix.
means line break and return in Mac OS. Go to the beginning of the next line, which is equivalent to the effect of n in Windows
t tab (move to the next column)
Additional note:
They are in the string represented by double quotes or delimiters Valid, not valid 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 symbol in the file:
windows: n
linux/unix: rn
The following uses code to illustrate three common methods of removing line breaks in strings in PHP
1. Use the escape character function
2. Use regular expressions to replace
3. It is recommended to use PHP system constants