替换 '\n' 的最简单方法是什么?与'
'?

发布于 2024-12-31 22:25:39 字数 278 浏览 3 评论 0原文

我在问题中找到了一些答案,但我不明白,并且这些解决方案中使用了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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

失眠症患者 2025-01-07 22:25:39

PHP 的内置函数 nl2br() 可以执行此操作。

PHP's built in function nl2br() does this.

我要还你自由 2025-01-07 22:25:39

nl2br 是最简单的

<?php echo nl2br($_POST['someTextArea']); ?>

nl2br is the simplest

<?php echo nl2br($_POST['someTextArea']); ?>
£冰雨忧蓝° 2025-01-07 22:25:39

在 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

稚气少女 2025-01-07 22:25:39

最简单、最可靠的方法是使用 PHP 内置的 nl2br() 函数。

http://php.net/manual/en/function.nl2br.php

但是,您似乎希望使用 javascript 来实现此目的。可以使用以下方法来完成:

value.replace(/\n/g,'<br />')

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:

value.replace(/\n/g,'<br />')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文