2012-09-30 15:21
浏览 33


I am creating a news publishing website and the only thing I can't do in the site is enter and show new-line.

There is a textarea in the site to write articles, if I press ENTER while I am typing, it will take me into a new line, but after having submitted all, and make query to mysql to pull and echo what I had typed in, the new line does not show up. All texts are next to each other. So, I was wondering if i could input and output newlines in textarea with the help of PHP?

图片转代码服务由CSDN问答提供 功能建议

我正在创建一个新闻发布网站,我在网站上唯一不能做的就是输入并显示新的 -线。

网站上有一个textarea来写文章,如果我在输入时按ENTER键,它会带我进入一个新的行,但是在提交了所有内容之后,并进行查询 mysql拉动并回显我输入的内容,新行没有显示出来。 所有文本都是彼此相邻的。 所以,我想知道我是否可以在PHP的帮助下输入和输出textarea中的换行符?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongluanjie8678 2012-09-30 15:23

    When you submit a form, you are submitting text.

    When you put that text into an HTML document, it is HTML.

    In HTML a new line is just a piece of white space with the same significance as a space or a tab.

    If you want new lines to show up, then you need to with wrap them with markup that causes them to be rendered (such as a <pre> element or an element with the white-space property set to cause them to render) or you need to replace them with suitable markup.

    A very primitive replacement would be PHP's nl2br function. A more advanced option would generate <p> elements and treat different numbers of sequential new lines differently (e.g. a Markdown parser such as the one used by Stackoverflow).

    解决 无用
    打赏 举报

相关推荐 更多相似问题