spaces in text ---> html

P

Peter Smith

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
 
M

Michael Capone

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top