【问题标题】:\n not working in text area\n 不在文本区域工作
【发布时间】:2012-01-04 02:00:53
【问题描述】:
<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

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

【问题讨论】:

    标签: php html textarea


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      • 2014-08-28
      • 1970-01-01
      相关资源
      最近更新 更多