in reply to Re: Replacing new lines in multi line text box form fields with <br>.
in thread Replacing new lines in multi line text box form fields with <br>.

Okay, good catch, I went to look how %INPUT was created and I saw a line where supposedly harmful characters were being stipped out, /n was one that was stripped.

I deleted that line and now this works

$INPUT{'comments'} =~s/\n/<br>/g;

Thanks, dumb mistake.

  • Comment on Re^2: Replacing new lines in multi line text box form fields with <br>.
  • Download Code

Replies are listed 'Best First'.
Re^3: Replacing new lines in multi line text box form fields with <br>.
by bart (Canon) on Nov 27, 2004 at 23:30 UTC
    You must be careful, if input comes from a TEXTAREA, your text will contain a CRLF combination for every end-of-line. You're better off replacing those with plain newlines, "\n", before you insert them in a database, for example. Or before feeding it back into the HTML for the next rendered page.
    s/\x0D\x0A/\n/g

    And don't forget to HTML-escape your string, when inserting it into the HTML, both for the TEXTAREA for edit and in the plain HTML for view, the former before you insert your <BR> tags — or you might end up escaping your freshly inserted tags, too.

    Oh, and it'd still be nice if you kept the newlines. For example:

    s/$/<BR>/mg;
    or
    s/\n/<BR>\n/g;