php - Why can't I wrap the content after posting it? ?
过去多啦不再A梦2017-05-24 11:33:29
0
4
638
Use the Enter key to break the line in the text box. When it is submitted to the database and then displayed on the front end, there is no line break. Why is this? What should I do if I want the same format as when I entered it?
You should note that line breaks are implemented using different characters in different environments. For example, in the input box (this is the case when submitting in your question) or in a text file or on the terminal, indicates a new line using the control character "nr" or "n" or "r" (refer to the constant PHP_EOL). In a browser environment (this is the case with the front-end mentioned in your question), line breaks are implemented by the "<br />" tag. So, when outputting, you need to convert "nr" or other line breaks into line break tags in the HTML language. Usually, the easier solution is the nl2br() function.
You should note that line breaks are implemented using different characters in different environments.
For example, in the input box (this is the case when submitting in your question) or in a text file or on the terminal,
indicates a new line using the control character "nr" or "n" or "r" (refer to the constant PHP_EOL).
In a browser environment (this is the case with the front-end mentioned in your question), line breaks are implemented by the "<br />" tag.
So, when outputting, you need to convert "nr" or other line breaks into line break tags in the HTML language.
Usually, the easier solution is the nl2br() function.
nl2br()
For details, please visit Baidu or view the official php documentation
Use pre tag to wrap the content when displaying
https://developer.mozilla.org...
Use rich text box
will be converted to newline character in
js
: