替换 '\n' 的最简单方法是什么?与'
'?
我在问题中找到了一些答案,但我不明白,并且这些解决方案中使用了AJAX。
现在我想找到一个简单的解决方案,用
替换“Enter Key”或 \n 以在 JavaScript 或 PHP 中查找新行。
对于
有没有什么方法可以使用 string.search()
并且不使用 AJAX 或 Jquery 或一些更难的解决方案?
I found some answers in the questions, but I didn't understand and AJAX was used in those solutions.
Now I want to find an easy solution to replace "Enter Key" or \n with <br>
to find new lines, in JavaScript or PHP.
For a text input(visitors comments) in a <form>
.
Is there any way to use string.search()
and don't using AJAX or Jquery or some harder solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
PHP 的内置函数 nl2br() 可以执行此操作。
PHP's built in function nl2br() does this.
nl2br 是最简单的
nl2br is the simplest
在 PHP 中使用 nl2br 更改新行以打破标签。 http://php.net/manual/en/function.nl2br.php
Use nl2br in PHP to change new lines to break tags. http://php.net/manual/en/function.nl2br.php
最简单、最可靠的方法是使用 PHP 内置的 nl2br() 函数。
http://php.net/manual/en/function.nl2br.php
但是,您似乎希望使用 javascript 来实现此目的。可以使用以下方法来完成:
The easiest and most reliable way to do this is using PHP's built in nl2br() function.
http://php.net/manual/en/function.nl2br.php
However, it looks like you would like to achieve this using javascript. That can be done using this: