繁体   English   中英

Textarea:按Enter键创建新行

[英]Textarea: pressing enter creates new line

当我在文本区域中按Enter键时,它会转到新行,但是在提交文本区域时,该新行不会显示。 我该如何工作? 它应该很简单,但是根据我的搜索和尝试,失败了。

<textarea style="{ white-space:pre; }"; name="texts" rows="3" cols="40"></textarea>

$texts = $_POST['texts'];

我认为您正在寻找nl2br()函数。

nl2br()

可能的问题是新行正在显示,但是您将其输出为html,因此它不会保留该新行。 当您输出为html时,需要将换行符转换为break标记。 您可以这样做:

//editing per comment advice. Apparently this method shouldn't be used since it doesn't replace all possible newline representations, although I dont remember having an issue with it.
//$string = str_replace("\n", "<br />", $string);
//as others mentioned, this is better and easier:
$string = nl2br($string);

也许我误解了这个问题,但这就是我从中得到的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM