Writing accented characters into HTML files?

  • Thread starter Kenneth McDonald
  • Start date
K

Kenneth McDonald

I'm having trouble when I write accented characters into HTML files;
though the accents appear properly in my terminal, they are badly
"messed up" in the HTML output. CGI.escape doesn't fix the problem,
because these are not "special" characters line < or >, but simply
accented e's, o's, etc. I'm assuming the problem has something to do
with a character set type mismatch between the file Ruby is writing
and what the browser (Firefox) expects, but I'm at a loss as to how to
correct it.

Any advice most appreciated,
Thanks,
Ken
 
B

Brian Candler

Kenneth said:
Any advice most appreciated,

Use hexdump -C on the file to see what the actual byte sequences are. If
these are single-byte characters then it's probably ISO-8859-1. If they
are two bytes then it's probably UTF-8.

You can use an XML declaration and/or a <meta> tag in the <head> section
to tell the browser which character set your document is in, and/or get
your web server to set the correct charset in the Content-Type header.
 
M

marc

Kenneth McDonald said...
I'm having trouble when I write accented characters into HTML files;
though the accents appear properly in my terminal, they are badly
"messed up" in the HTML output. CGI.escape doesn't fix the problem,
because these are not "special" characters line < or >, but simply
accented e's, o's, etc. I'm assuming the problem has something to do
with a character set type mismatch between the file Ruby is writing
and what the browser (Firefox) expects, but I'm at a loss as to how to
correct it.

Any advice most appreciated,

Start by ensuring that you have the following at the top of <head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Also, post the "messed up" characters; they'll tell us something about
the encoding problem.

Oh, and make sure your editor is writing utf-8.
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top