Explode textarea separated by newline

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Explode textarea separated by newline

Post by anjanesh »

I have <textarea name="txtA"></textarea>
$lines = explode("\n",$_POST['txtA']); doesnt seem to split into lines. I tried \r\n to but still $lines is still a string and not an array.
Any solutions ?
Thanks
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Seems odd.. could you post a bit more code?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

try

Code: Select all

$textarea = nl2br($_POST['txtA']);
explode("<BR />", $textarea);
that's the only thing that I can thing of
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

what is the output if you print it directly. does it have new-lines in them :?:
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

I had to do this to make it work correctly.

Code: Select all

$lines = explode("<br>",str_replace("\n","<br>",$_POST['txtA']));
Saibot - On printing it directly it'll print with \n in the html source - obviously it'll be linear in the output - dont know why explode could not use \n as separator.
I once saw another thread regarding this - he too had the same problem - he had to replace \n with something to explode.
Thanks
Post Reply