Page 1 of 1

Adding line breaks to text

Posted: Sun Apr 03, 2005 8:28 am
by cbrian
How would I add line breaks to a text area after it is submitted like this:

Text

Text2
Text3

would be

Text<br>
<br>
Text2<br>
Text3<br>

Use nl2br

Posted: Sun Apr 03, 2005 8:58 am
by marike
Unless I'm missing something, you could use nl2br like so:

Code: Select all

<?php
$string = "Text\nText2\nText3\n";

echo nl2br($string);
?>

And if you have more sophisticated needs it would be pretty easy to write a function that uses nl2br. Hope this helps.

Posted: Sun Apr 03, 2005 9:42 am
by cbrian
That works. Thanks!