Turning New Lines Into HTML Line Breaks

Posted: February 16, 2011 in ColdFusion

Many times you need to process textarea field content in ColdFusion and add HTML line breaks so it actually displays correctly on screen or in an email. An easy way to accomplish this is to replace the character codes 10 and 13 with <br>:

Replace(textVar, "#Chr(10)##Chr(13)#", "<br>", "all")

This code takes:

Line 1
Line 2

Line 3

And turns it into:

Line 1<br>
Line 2<br>
<br>
Line 3
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s