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

Lots of people giving you variations on the theme of how to make the changes you asked for, but no-one stepping back and asking what you're trying to achieve.

Changing newlines to <br> tags is a display issue. You should only be making changes like this to a copy of the data that it being displayed to the user in a browser. If you're storing the data somewhere for processing later then you should store it in its original format.

As an example of why this approach it useful consider the change from HTML to XHTML. Currently it looks like you are displaying the data as HTML (as <br> is an HTML tag), but eventually you are going to want to display the data as XHTML instead. The equivalent tag in XHTML is <br/>.

If you're storing the original version of the data then you can decide what format you are planning to display it in at the time when you display it. If you save it as HTML then you're making the decision that you're always going to display it as HTML. Which may not be true in two years time.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

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

Replies are listed 'Best First'.
Re^2: Replacing new lines in multi line text box form fields with <br>.
by awohld (Hermit) on Nov 26, 2004 at 13:33 UTC
    I'm taking the data and storing it a database as text. So from what you're saying I'd take the data as I get it out of my database and then replace the /n with what ever the equilivent tag is for what I'm displaying.

      Yes. That's exactly what I'm saying.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg