473,513 Members | 3,208 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1882
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
2556
by: phil hunt | last post by:
Does anyone know of a text-to-HTML processing program, ideally written in Python because I'll probably be wanting to make small modifications to it, which is simple and straightforward to use and...
4
4880
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
6
7061
by: Joerg Battermann | last post by:
Hey there, mmmm does anyone know a library or anything I can use to convert plaintext to html real quick and vice-versa? Regex surely would do the trick to a certain level, but maybe there's...
1
2780
by: Husam | last post by:
Hi EveryBody: I have this code which convert RTF Text to HTML ? but I think it is written by vb.classic, I want some body help my in writting this code by Vb.Net ? but if it is already writen by...
1
2009
by: Husam | last post by:
Hi EveryBody: I got this code from one newsgroup in google, the one who post this code claim that this code convert Text to HTML , if that is right can Any body help me and expline for me how...
0
1250
by: Husam | last post by:
Hi EveryBody: I got this code from one newsgroup in google, the one who post this code claim that this code convert Text to HTML , if that is right can Any body help me and expline for me how...
1
4616
by: Stu Lock | last post by:
Hi, I have an app that has beenusing the JMail COM component to generate emails. I would like to switch to the using the .Net 2.0 MailMessage object instead - as it is more portable. The...
0
1861
by: Rey | last post by:
Howdy all. Am using visual web developer 2005 (vb), xp pro sp2. In testing of the system.net.mail to send email from an aspx page where I'm pulling the email contents from a textbox, find that...
2
1090
by: praveen1983 | last post by:
Hi al I need a solution for for converting my text to HTML using C# code. for Ex.. if i am entering a some text in a textarea and formatting the text and i want to convert those foramtted text...
0
7254
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5677
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
1585
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.