By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,965 Members | 2,043 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,965 IT Pros & Developers. It's quick & easy.

replacing text for use in a text area...

P: n/a
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

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
WindAndWaves wrote:
Hi Gurus
Hi,

I am no guru. :P

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
Suppose $content contains the htmlformatted body of the email:

$content = str_replace("<br>","\n",$content);
b. get rid of double spaces and tabs before the text is loaded in the
textarea
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.
c. put the <BR>s back in when the user is finished with editing the
message.
$content = str_replace("\n","<br>",$content);

Is there a way to do this?

TIA

- Nicolaas

Regards,
Erwin Moller
Jul 17 '05 #2

P: n/a
Suppose you have the text in the $content variable

a.$content=br2nl($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

Jul 17 '05 #3

P: n/a
I noticed that Message-ID: <i1*******************@news.xtra.co.nz> from
WindAndWaves contained the following:
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.


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/
Jul 17 '05 #4

P: n/a

"Geoff Berrow" <bl@ckdog.co.uk> wrote in message
news:1i********************************@4ax.com...
I noticed that Message-ID: <i1*******************@news.xtra.co.nz> from
WindAndWaves contained the following:
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.


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.


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
Jul 17 '05 #5

P: n/a
WindAndWaves wrote:
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

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:

http://www.dynarch.com/projects/htmlarea/

Sacs
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.