Text Area New line
Posted: Mon Oct 01, 2012 6:22 am
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>
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
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);
}
} 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