问题描述
字符串输入来自textarea,用户应在其中输入新行中的每一项.
The string input comes from textarea where users are supposed to enter every single item on a new line.
在处理表单时,很容易将textarea输入分解成单个项目数组,如下所示:
When processing the form, it is easy to explode the textarea input into an array of single items like this:
$arr = explode("\n", $textareaInput);
它可以正常工作,但是我担心它不能在其他系统中正常工作(我目前只能在Windows中进行测试).我知道换行符表示为\ r \ n或跨不同平台仅表示为\ r.上面的代码行在Linux,Solaris,BSD或其他OS上也能正常工作吗?
It works fine but I am worried about it not working correctly in different systems (I can currently only test in Windows). I know newlines are represented as \r\n or as just \r across different platforms. Will the above line of code also work correctly under Linux, Solaris, BSD or other OS?
推荐答案
'\ r'本身作为行终止符是一种旧的约定,现在不再使用了(因为OSX是基于Unix的).
'\r' by itself as a line terminator is an old convention that's not really used anymore (not since OSX which is Unix based).
您的explode
会没事的.对于Windows用户,只需在每个结果元素中的'\ r'下trim
.
Your explode
will be fine. Just trim
off the '\r' in each resulting element for the Windows users.
这篇关于可靠地从字符串中删除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!