The following is my solution to this problem. At last, I fully understood it. It was a real risk of turning around the ship.
1.You must know that the linefeed in textarea is \ n (I found that the Enter key is \ n, as if it is \ r \ n in Linux)
2.Before using nl2br, Please carefully read the manual explanation. I am depressed. Generally, it is understood that \ n is converted to <br>. Actually, it is not:
Refer to the PHP manual for explanation:
Nl2br-inserts HTML line breaks before all newlines in a string
ReturnsStringWith '<br/>' inserted before all newlines
It means to Insert a new row before it <br/>
The w3cschool statement is as follows:
The nl2br () function inserts an HTML Line Break (<br/>) before each new line (\ n) in the string ).
Therefore, nl2br () can be inserted. <br> but \ n still exists. For example, the source code of the string is program \ n, we use programs after nl2br <br> \ n alive. So what we can see is:
Program
Life network -------- line feed, because there is \ n in the source code
3. use the PHP function and str_replace to replace the function, such as str_replace ('\ n',' <br/> '). The problem is that the replacement is not successful and has never been replaced, after a long time, I even began to doubt whether the linefeed in textarea is \ n. Now I think it is too shaken, O (character _ character) O... In fact, after I replaced \ n/n separately, I intuitively told myself that I had entered a dead end. This is not a way to solve the problem, and there must be a fundamental error. Suddenly I thought about whether it would be a single or double quotation mark, so I changed str_replace ('\ n',' <br/> ') to str_replace ("\ n ", "<br/>. Great sweat!
I opened the manual and read the single quotation marks and double quotation marks again. I finally breathed a sigh of relief. I still have my own basic questions. php is easy to use and I still need to pay attention to the details.
The manual details the single double quotation marks:
The simplest way to specify a simple string is to use single quotes (Characters'.
To represent a single quotation mark, a backslash (\) Escape, same as many other languages. If a backslash is required before single quotes or at the end of a string, two backslashes are required.Note that if you try to escape any other character, the backslash itself will be displayed! Therefore, you do not need to escape the backslash itself.
If double quotation marks (") are used to enclose strings, PHP understands the escape sequence of more special characters:
Table 6-1. escape characters
Sequence
Description
\ N
Line feed (LF or ASCII characters 0 × 0a (10 ))
\ R
Press enter (Cr or ASCII character 0 × 0d (13 ))
\ T
Horizontal tab (HT or ASCII character 0 × 09 (9 ))
\\
Backslash
\ $
Dollar sign
\"
Double quotation marks
\ [0-7] {1, 3}
This regular expression matches a character in the octal symbol.
\ X [0-9a-fa-f] {1, 2}
This regular expression matches a character in the hexadecimal notation.
In addition, if you try to escape any other characters, the backslash itself will be displayed!
---Now, the textarea line feed problem is clear, not line break or nl2br. It is because all transfers only exist in double quotation marks, and single quotation marks only process characters in PHP. What a depressing mistake. Remember it later.
Line breaks in textarea