\n 在文本区域中不起作用

发布于 2024-12-24 20:19:12 字数 402 浏览 2 评论 0原文

<textarea rows="18" cols="80" style="resize:none;">
<?php
    $str = str_replace('<br>', '\n', 'some text<br><br>another line of text');
    echo($str);
?>
</textarea>

输出是

some text\n\nanother line of text

这是我想要的输出。

some text

another line of text

有谁知道问题出在哪里吗? 提前致谢

<textarea rows="18" cols="80" style="resize:none;">
<?php
    $str = str_replace('<br>', '\n', 'some text<br><br>another line of text');
    echo($str);
?>
</textarea>

Output is

some text\n\nanother line of text

This is the output that i want.

some text

another line of text

Anyone know wheres the problem?
Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

梦幻的味道 2024-12-31 20:19:12

单引号中的反斜杠按字面意思解释。您想要双引号:

$str = str_replace('<br>', "\n", 'some text<br><br>another line of text');
///                        ^  ^

有关在 php 中编写字符串文字的不同方法的详细信息,请参阅 官方文档

Backslashes in single quotes are interpreted literally. You want double quotes:

$str = str_replace('<br>', "\n", 'some text<br><br>another line of text');
///                        ^  ^

For details about the different ways to write string literals in php, refer to the official documentation.

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