php -\n 不在文本区域工作

标签 php html textarea

<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

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

最佳答案

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

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

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

关于php -\n 不在文本区域工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8721143/

相关文章:

javascript - 按类型或类而不是索引获取子节点

html - 如何测试移动设备的网站

javascript - 如何使用 Javascript 获取文本区域内字符中的鼠标位置

javascript - 如何获取文本区域内文本的高度

php - 在 windows 和 linux 服务器中 explode 错误\r\n 和\n

PHP mysql_stmt::fetch() 给出 PHP fatal error 内存耗尽

php - 将Mysql结果集转换为JSON会打印相同字段两次

php - 从 javascript 触发 php 函数

php - 将 session 数据存储在文件与数据库中的优缺点是什么?

javascript - html5 拖放使用 jquery(不是 jquery UI)