The string input comes from textarea where users are supposed to enter every single item on a new line.
When processing the form, it is easy to explode the textarea input into an array of single items like this:
$arr = explode("\n", $textareaInput);
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’ by itself as a line terminator is an old convention that’s not really used anymore (not since OSX which is Unix based).
Your
explodewill be fine. Justtrimoff the ‘\r’ in each resulting element for the Windows users.