<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/