Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

explode textarea php (at new lines)

Tags:

php

explode

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")

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.

like image 845
Chris Muench Avatar asked Aug 14 '11 16:08

Chris Muench


2 Answers

This will do the trick given \r\n, \r or \n:

preg_split('/\r\n|[\r\n]/', $_POST['thetextarea']) 
like image 89
Long Ears Avatar answered Oct 14 '22 22:10

Long Ears


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.1 for more info.

like image 20
PeeHaa Avatar answered Oct 14 '22 22:10

PeeHaa