Jump to content

Recommended Posts

Yes you'll want to use explode, like effigy has shown, however if you are dealling with user input from a form field not all OSs use the same whitespace character for newlines.

\r\n - Windows
\r - Mac
\n - Linux

So if you are dealing with user input from a textarea in a form, you'll wnat to do something like this:
[code=php:0]// Convert other OS newlines into the linux newline char
$words = str_replace(array("\r\n", "\r"), "\n", $_POST['words_txtbox']);

$word = explode("\n", $words);[/code]
Link to comment
https://forums.phpfreaks.com/topic/20869-textarea-split/#findComment-92518
Share on other sites

Thanks for the catch; however, textarea's are not platform-specific. See [url=http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4]application/x-www-form-urlencoded[/url]. When dealing with form data:

[quote]
Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
[/quote]
Link to comment
https://forums.phpfreaks.com/topic/20869-textarea-split/#findComment-92542
Share on other sites

[quote author=effigy link=topic=108180.msg435025#msg435025 date=1158341226]
Thanks for the catch; however, textarea's are not platform-specific. See [url=http://www.w3.org/TR/1999/REC-html401-19991224/interact/forms.html#h-17.13.4]application/x-www-form-urlencoded[/url]. When dealing with form data:

[quote]
Line breaks are represented as "CR LF" pairs (i.e., `%0D%0A').
[/quote]
[/quote]

Then it should be [code]<?php

$string = "Hello\nNo\nYou";
print_r(explode("\r\n", $string));

?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/20869-textarea-split/#findComment-92563
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.