爆炸 textarea php(在新行)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7058168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
explode textarea php (at new lines)
提问by Chris Muench
can I do:
我可不可以做:
explode("\n", $_POST['thetextarea']);
and have it work on all platforms? (The question I am asking is will it ever be \r\n and not just \n")
并在所有平台上工作?(我要问的问题是它会不会是 \r\n 而不仅仅是 \n”)
EDIT:
编辑:
I forgot to mention that I am saving $_POST['thetextarea'] to a mysql database VARCHAR 255. It seems \r\n is converted to \n.
我忘了提到我正在将 $_POST['thetextarea'] 保存到 mysql 数据库 VARCHAR 255。似乎 \r\n 已转换为 \n。
回答by Long Ears
This will do the trick given \r\n
, \r
or \n
:
这将完成给定的技巧\r\n
,\r
或者\n
:
preg_split('/\r\n|[\r\n]/', $_POST['thetextarea'])
回答by PeeHaa
You should use:
你应该使用:
explode("\r\n", $_POST['thetextarea']);
It will always be the same.
它永远是一样的。
Browsers and other user-agents will make sure they are :-)
浏览器和其他用户代理将确保它们是 :-)
See http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1for more info.
有关更多信息,请参阅http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2.1。
回答by Sascha Galley
You could also use the PHP_EOL
constant:
您还可以使用PHP_EOL
常量:
explode(PHP_EOL, $_POST['thetextarea']);
回答by Jatin Babbar
You can do something like this:
你可以这样做:
$text = trim($_POST['textareaname']);
$text = nl2br($text);