views:

33

answers:

2

Im trying to code a php script that will loop a process for each line in a Textarea post. I was wondering if someone can post an example.

+1  A: 
foreach(explode("\n", $text) as $line) {
    // do something
}

See http://uk2.php.net/manual/en/function.explode.php

Gordon
Browsers can be funny about what chars they use to separate lines in a textarea -- i've seen a lot that just use `\x0d`, while some others might use `\x0d\x0a`. I've never seen one yet that just uses `\x0a`, but i guess it's possible. May also depend on the textarea's settings, and whether soft wrapping is enabled.
cHao
A: 

You might have to use \r\n instead of just \n for textarea (I remember figuring it out for quite a while)

Heiko