replacing text for use in a text area...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WindAndWaves

    #1

    replacing text for use in a text area...

    Hi Gurus

    I have a PHP page that allows a user to preview an email and then send it
    if(s)he is happy with it.

    Otherwise, they can click on an edit button and edit the text of the
    message. The text is then shown in a textarea element.

    While in situation A (the preview), a bit of formatting is useful (e.g
    <BR>), all of this formatting is a nuisance in the textarea.

    Basically, I would like to do the following:
    a. replace <BR> with a line break for the textarea
    b. get rid of double spaces and tabs before the text is loaded in the
    textarea
    c. put the <BR>s back in when the user is finished with editing the message.

    Is there a way to do this?

    TIA

    - Nicolaas



  • Erwin Moller

    #2
    Re: replacing text for use in a text area...

    WindAndWaves wrote:
    [color=blue]
    > Hi Gurus[/color]

    Hi,

    I am no guru. :P
    [color=blue]
    >
    > I have a PHP page that allows a user to preview an email and then send it
    > if(s)he is happy with it.
    >
    > Otherwise, they can click on an edit button and edit the text of the
    > message. The text is then shown in a textarea element.
    >
    > While in situation A (the preview), a bit of formatting is useful (e.g
    > <BR>), all of this formatting is a nuisance in the textarea.
    >
    > Basically, I would like to do the following:
    > a. replace <BR> with a line break for the textarea[/color]

    Suppose $content contains the htmlformatted body of the email:

    $content = str_replace("<b r>","\n",$conte nt);
    [color=blue]
    > b. get rid of double spaces and tabs before the text is loaded in the
    > textarea[/color]

    Bad idea I think.
    You are changing the makeup somebody used.
    eg this
    or this

    But if you want to: use the same str_replace to find tabs.
    Write a little routine to remove more than 1 space.
    [color=blue]
    > c. put the <BR>s back in when the user is finished with editing the
    > message.[/color]

    $content = str_replace("\n ","<br>",$conte nt);
    [color=blue]
    >
    > Is there a way to do this?
    >
    > TIA
    >
    > - Nicolaas[/color]


    Regards,
    Erwin Moller

    Comment

    • claudel@gmail.com

      #3
      Re: replacing text for use in a text area...

      Suppose you have the text in the $content variable

      a.$content=br2n l($content);

      b. trim($content). also for trimming the spaces, tabs in the left side
      you can use ltrim, same for the right side where you can use rtrim. The
      following characters will be removed from the beginning&end of the
      content:

      " " (ASCII 32 (0x20)), an ordinary space.
      "\t" (ASCII 9 (0x09)), a tab.
      "\n" (ASCII 10 (0x0A)), a new line (line feed).
      "\r" (ASCII 13 (0x0D)), a carriage return.
      "\0" (ASCII 0 (0x00)), the NUL-byte.
      "\x0B" (ASCII 11 (0x0B)), a vertical tab.
      c. $content=nl2br( $content);

      Hope this helps.
      Clau

      Comment

      • Geoff Berrow

        #4
        Re: replacing text for use in a text area...

        I noticed that Message-ID: <i1sEd.6581$mo2 .446301@news.xt ra.co.nz> from
        WindAndWaves contained the following:
        [color=blue]
        >I have a PHP page that allows a user to preview an email and then send it
        >if(s)he is happy with it.
        >
        >Otherwise, they can click on an edit button and edit the text of the
        >message. The text is then shown in a textarea element.
        >
        >While in situation A (the preview), a bit of formatting is useful (e.g
        ><BR>), all of this formatting is a nuisance in the textarea.[/color]

        Does that mean you intend to send html email?

        If not (which I recommend) simply enclose the preview with <pre></pre>
        tags and leave all line breaks and tabs as they are.
        --
        Geoff Berrow (put thecat out to email)
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • WindAndWaves

          #5
          Re: replacing text for use in a text area...


          "Geoff Berrow" <bl@ckdog.co.uk > wrote in message
          news:1iv7u0ttnv vf2d81cr3k6tq45 clu2pbokp@4ax.c om...[color=blue]
          > I noticed that Message-ID: <i1sEd.6581$mo2 .446301@news.xt ra.co.nz> from
          > WindAndWaves contained the following:
          >[color=green]
          > >I have a PHP page that allows a user to preview an email and then send it
          > >if(s)he is happy with it.
          > >
          > >Otherwise, they can click on an edit button and edit the text of the
          > >message. The text is then shown in a textarea element.
          > >
          > >While in situation A (the preview), a bit of formatting is useful (e.g
          > ><BR>), all of this formatting is a nuisance in the textarea.[/color]
          >
          > Does that mean you intend to send html email?
          >
          > If not (which I recommend) simply enclose the preview with <pre></pre>
          > tags and leave all line breaks and tabs as they are.[/color]

          Hi Geoff

          Good point. Thank you, yes, I am sending HTML email (I think - I have taken
          over someone else his site). Let me have a look into this.... perhaps we
          can change it to a text only email - although the email only contains a
          couple of <BR>s....

          Thank you


          - Nicolaas


          Comment

          • Sacs

            #6
            Re: replacing text for use in a text area...

            WindAndWaves wrote:[color=blue]
            > Hi Gurus
            >
            > I have a PHP page that allows a user to preview an email and then send it
            > if(s)he is happy with it.
            >
            > Otherwise, they can click on an edit button and edit the text of the
            > message. The text is then shown in a textarea element.
            >
            > While in situation A (the preview), a bit of formatting is useful (e.g
            > <BR>), all of this formatting is a nuisance in the textarea.
            >
            > Basically, I would like to do the following:
            > a. replace <BR> with a line break for the textarea
            > b. get rid of double spaces and tabs before the text is loaded in the
            > textarea
            > c. put the <BR>s back in when the user is finished with editing the message.
            >
            > Is there a way to do this?
            >
            > TIA
            >
            > - Nicolaas
            >
            >
            >[/color]
            May be a little off-topic, but you might want to look at HTMLArea for
            _really_ fancy textareas. It is very cool Javascript that adds a full
            gui editor toolbar to textareas:



            Sacs

            Comment

            Working...