Click to See Complete Forum and Search --> : eqivilent to nl2br()


chrismartz
10-01-2004, 05:58 PM
does anyone know what the ASP eqivilent to the php code nl2br() is?

russell
10-01-2004, 07:09 PM
No exactly equivalent function. You can do this:

Response.Write "Line<br>Break"

You could use the replace() funtion:

Dim str
str = "Line\nBreak"
Response.Write Replace(str, "\n", "<br>")

Finally, force line breaks in the code (not the html) like this:

Response.Write "A string" & vbCrLf

chrismartz
10-01-2004, 07:30 PM
what should i use for a comment area that gets comments and if the user puts a return into the comment area it saves it in the db with that return?

buntine
10-01-2004, 10:08 PM
Like russell said, use the Replace function to replace \n with <br />. Just save HTML in the database, there is no need to store the newline character.

Regards.

chrismartz
10-02-2004, 12:01 AM
How would I put:Dim str
str = "Line\nBreak"
Response.Write Replace(str, "\n", "<br>")
into comment = Replace(Request.Form("comment"), "'", "''") while keeping the replace function there?

buntine
10-02-2004, 03:38 AM
You've done this before.

comment = Replace(Request.Form("comment"), "'", "''")
comment = Replace(comment, vbCrLf, "<br />")

By the way, ASP does not use the same escape sequences as c-style languages. So, using \n will not work. You need to use vbCrLf.

Regards.