search

Home  >  Q&A  >  body text

php - Why can't I wrap the content after posting it? ?

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梦2781 days ago662

reply all(4)I'll reply

  • 巴扎黑

    巴扎黑2017-05-24 11:35:29

    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.

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-24 11:35:29

    nl2br()

    For details, please visit Baidu or view the official php documentation

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-05-24 11:35:29

    Use pre tag to wrap the content when displaying

    https://developer.mozilla.org...

    reply
    0
  • PHP中文网

    PHP中文网2017-05-24 11:35:29

    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/>");

    reply
    0
  • Cancelreply