Page 1 of 1

Text Area New line

Posted: Mon Oct 01, 2012 6:22 am
by Live24x7
Please help me with this.

I have a text area where a user submits numbers - each new number in a new row.
I need to take up each number in the row and do some maths on it. // say i want to just echo it for now

<textarea name="data"></textarea>

Code: Select all

if(isset($_POST['submit']))
{  
        $data = ($_POST['data'])); // 
        $array=explode( "\r\n", $data );
        for($i=0; $i < count($array); $i++)
       {
       echo preg_replace('/\r\n|\r|\n/m','',$array[$i]); //or the next 
       echo nl2br($array[$i], false);
       }
 } 
the problem is i am not being able to get away with the \r\n after each number.
i tried both preg replace and nl2br but the output is like 10\r\n20\r\n30\r\n40\r\n
where as i want it like:
10
20
30
40

Any help would be appreciated

Re: Text Area New line

Posted: Mon Oct 01, 2012 6:35 am
by Live24x7
pls ignore this.. got a solution. turns out that i was using htmlentities & mysql_real_escape_string prior to explode and that was modifying things out :)