Replacing all "special characters" with code

M

Mike

I'm currently changing all of my "special characters," like &, ",
whitespace, etc to their HTML counterparts manually (& "
$nbsp;). The problem is, there could be several that I'm forgetting.

Is there a faster way to transfer all of these characters at once?

On a similar note, any thoughts on a good replacement for a single
quote? I'm using ´, but it's not quite the same.

TIA,

Mike
 
B

Ben Morrow

I'm currently changing all of my "special characters," like &, ",
whitespace, etc to their HTML counterparts manually (& "
$nbsp;). The problem is, there could be several that I'm forgetting.

Is there a faster way to transfer all of these characters at once?

I usually use
s/&/&/g;
s/"/"/g;
s/</&lt;/;
s/>/&gt;/;
s/([^[:ascii:]])/sprintf '&#x%04X;' ord $1/ge;
On a similar note, any thoughts on a good replacement for a single
quote? I'm using &acute;, but it's not quite the same.

Err, no, they're completely different. The correct replacement is
&apos;, but replacement is not necessary and IIRC some versions of IE
don't correctly recognize it.

Ben
 
T

Tore Aursand

I'm currently changing all of my "special characters," like &, ",
whitespace, etc to their HTML counterparts manually (&amp; &quot;
$nbsp;). The problem is, there could be several that I'm forgetting. Is
there a faster way to transfer all of these characters at once?

Take a look at HTML::Entities. Maybe not faster, but at least you get to
have all the characters encoded correctly.
 
M

Michele Dondi

I'm currently changing all of my "special characters," like &, ",
whitespace, etc to their HTML counterparts manually (&amp; &quot;
$nbsp;). The problem is, there could be several that I'm forgetting.

Even if it does just the opposite transformation, you may be
interested in giving a peek into Tom Christiansen script mentioned at
'perldoc -q HTML'!


Michele
 

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,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top