Text Area New line

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
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Text Area New line

Post 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
Live24x7
Forum Contributor
Posts: 194
Joined: Sat Nov 19, 2011 9:32 am

Re: Text Area New line

Post 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 :)
Post Reply