Jump to content

Textarea Split


Baving

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.