从textarea输入中捕获换行符 [英] Capture newline from a textarea input

查看:86
本文介绍了从textarea输入中捕获换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的html中有一个textarea表单。如果用户在两个句子之间输入数据应该被带到我的PHP。



目前如果用户输入:

  Apple 
Google
MS

我的PHP代码是:

  $ str = $ _POST [field]; 

echo $ str;

我得到

  Apple Google MS 

作为输出。我希望输出像这样

  Apple 
Google
MS

我该怎么办? >尝试 nl2br() 代替:

  echo nl2br($ str); 


I have a textarea form in my html. If the user hits enter between 2 sentences that data should be carried over to my PHP.

Currently if the user enters:

Apple
Google
MS

and my PHP code is:

$str = $_POST["field"];

echo $str;

I get

Apple Google MS 

as the output. I want output to be like this

Apple
Google
MS

what should I do?

解决方案

Try nl2br() instead:

echo nl2br($str);

这篇关于从textarea输入中捕获换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆