jj2
jj2

Reputation: 966

ColdFusion EncodeForHTML and newlines

What characters do newlines (\n) and carriage returns (\r) get converted to when using EncodeForHTML in ColdFusion? I have tried everything I can think of (or find online) but cannot find what I need to use in my REReplace statement to convert to break (br) tags after the encoding (I need to do this for display purposes).

What I would like to do is something like

#REReplace(EncodeForHTML(myVar), "html encoded newline etc chars", "<br />", "all")#

However, because I can't figure out what the newlines and carriage returns are being converted to the only way I can get it to work it to do a REReplace before and after EncodeForHTML, which doesn't seem very sensible or efficient. For example:

#REReplace(EncodeForHTML(REReplace(myVar, "\r\n|\n\r|\n|\r", "<br />", "all")), "&lt;br &##x2f;&gt;", "<br />", "all")#

I am using CF 10.

Upvotes: 4

Views: 1215

Answers (1)

jj2
jj2

Reputation: 966

\n is being encoded as &#xa;

\r is being encoded as &#xd;

So the following simplified code now works:

#REReplace(EncodeForHTML(myVar), "&##xa;&##xd;|&##xd;&##xa;|&##xa;|&##xd;", "<br />", "all")#

Upvotes: 6

Related Questions