Results 1 to 5 of 5

Thread: Text Area to HTML [resolved]

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Resolved Text Area to HTML [resolved]

    I want to put a text area on a page that I am working on, this text area is for the user to put in a message email body, the user types up the message body as plain text but i would like to have it converted to HTML. So that if the user enters 3 paragraphs separted by blank lines, when the text from the textarea get inserted in the email that gets sent out it doesnt look like a big chunk of information but separted into several paragraphs.

    Does anyone have any idea of how to do this? Examples would be best.

    Thanks to all that reply.
    Last edited by mrstuff68; Oct 12th, 2006 at 09:12 PM.

  2. #2
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Text Area to HTML

    If you send the textarea contents in plain text then you don't need to worry about the line changes being in HTML: from plain text view they are there already. Of course, you can also send the textarea contents in HTML... so do you really need to send as HTML? The easiest you can do is to do replace for line break tag.

    You didn't tell which server side language you are using. PHP, JSP, ASP, Perl?

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Re: Text Area to HTML

    Merri, I am using ASP and sending out an email. But I am hardcoding the header which has an image and some standard text, and also hardcoding the footer, which is a thank you with a few links, I am only allowing the user to enter the body of the html and figured that i need to change from plain text to html, in order to get this accomplished, becuase I am sending an html email. So what you are saying is that i can just drop the plain text into the html and it will work fine?

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Text Area to HTML

    In this case it won't work as you said you're sending an HTML mail. The easiest replace code would be something like
    VB Code:
    1. 'note: actually writing as classic VB since it is closest to ASP that I know
    2.    strHTML = Replace(strTextarea, vbLf, "<br>")
    vbLf represents the line change character. In PHP and JavaScript you get this with "\n" (if I remember correctly). I don't know if ASP pages are served with CRLF (Windows/DOS style) or just LF (UNIX/Linux style).

    A more sophisticated way would be to do multiple replaces so you'd end up with something like this:
    HTML Code:
    <p>Line one.<br>Line two.</p><p>Second paragraph</p>
    This would just be more correct in context sense, but admittedly harder to code.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Apr 2002
    Posts
    492

    Re: Text Area to HTML

    Merri,

    The text replace worked like a charm, just what I was looking for.

    Thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width