469,916 Members | 1,896 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,916 developers. It's quick & easy.

spaces in text ---> html

Hi

I am writing a message board, and the text is entered in a text box and
outputted in HTML. How can I keep the spaces formatting (ie use  's)
in the html output??

I use the standard decode lines:
$value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
but when I use

$value =~ tr/+/"\&nbsp\;"/;

I get repeated &'s instead of spaces. Any help much appreciated..

- Peter
Jul 19 '05 #1
1 1788
tr// is a one-to-one transformation, meaning there (should be) the
same # of characters in each operand. Thus, the line:

$value =~ tr/+/"\&nbsp\;"/

will be interpreted as "translate a + sign to a quote, then
translate... oops, all done!" since there's only the plus sign on the
left.

Try:

$value =~ s/\+/\&nbsp\;/g;

to get the desired effect. Note the \+ in the construct above.

MAC
"Peter Smith" <ps*****@SparnBlock.bigpond.net.au> wrote in message news:<aw******************@news-server.bigpond.net.au>...
Hi

I am writing a message board, and the text is entered in a text box and
outputted in HTML. How can I keep the spaces formatting (ie use &nbsp;'s)
in the html output??

I use the standard decode lines:
$value =~ tr/+/ /;

$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
but when I use

$value =~ tr/+/"\&nbsp\;"/;

I get repeated &'s instead of spaces. Any help much appreciated..

- Peter

Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by phil hunt | last post: by
6 posts views Thread by Joerg Battermann | last post: by
1 post views Thread by Husam | last post: by
1 post views Thread by Husam | last post: by
reply views Thread by Husam | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.