php - Why can't I wrap the content after posting it? ?
过去多啦不再A梦
过去多啦不再A梦 2017-05-24 11:33:29
0
4
590

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?

过去多啦不再A梦
过去多啦不再A梦

reply all(4)
巴扎黑

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.

Peter_Zhu

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...

洪涛
  1. Use rich text box

  2. will be converted to newline character in js:

var text= 'aaa bbb ccc';
text = text.replace("\n\r", "<br/>");
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!