Reverse escaping in HTML

C

Csaba2000

Most of the time when I think of escaping characters in HTML,
it's ensuring that I can print certain characters instead of havingt them
be interpreted by the HTML parser. (eg. I can have a less than sign
rendered by using "<" (without the quotes)).

But I want to go in the other direction. I want to be able to encode
arbitrary characters so that when they arrive at the browser they're
interpreted correctly at the appropriate time.

So, for example, I'd like to be able to do something like (note the
inner single quote):
<img src="Dinner.jpg" alt='"He's eating like a horse", she said'>

I'm after a generic solution, if possible, as the above example is
a fairly simplistic illustration. In addition, I may want to encode
other characters such as the alt itself or the symbols such as
the "less than" or "equal" sign (so this might actually be two
questions).

Thanks for any tips,
Csaba Gabor
 
B

Brian

Csaba2000 said:
I'd like to be able to do something like (note the inner single
quote): <img src="Dinner.jpg" alt='"He's eating like a horse", she
said'>

<img src="Dinner.jpg" alt="&quot;He's eating like a horse,&quot; she
said">

You can do it other ways, too; I do it this way, because it keeps my
attributes consistently double-quoted.
I'm after a generic solution, if possible, as the above example is
a fairly simplistic illustration.

I don't know what you mean by that.
In addition, I may want to encode other characters such as the alt
itself

The alt itself? What is that?
or the symbols such as the "less than"

<img src="image.jpg" alt="n &lt; t">

<img src="image.jpg" alt="n < t">

(I must be misunderstanding you.)
or "equal" sign (so this might actually be two questions).

<img src="image.jpg" alt="e = m*c squared">
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top