in reply to encode charset

Note that utf8 and utf-8 are not the same thing, normally you deal with utf-8.

You have to take a few steps to get utf-8 working:

1) You need to set up STDOUT: binmode STDOUT, ':encoding(UTF-8)';

2) Send a header with the correct charset: print "Content-Type: text/html charset=utf-8\n\n";

3) ensure that your HTML doesn't contain a http-equiv meta tag with a different charset.

To test it, open your page with Firefox, press Ctrl+I, and check which encoding it thinks the page is in.

And make sure to read perluniintro, perluniintro and perlunifaq.

Replies are listed 'Best First'.
Re^2: encode charset
by Akoya (Scribe) on Mar 06, 2008 at 21:48 UTC
    In order to inform your browser that you are sending utf8 characters, add this to your head section:
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
      No! There's no reason to put that in the HTML when you send a correct header.

      You'll only get problems when you change the charset, and you forget to adjust it in both places.

      The meta header can only be parsed if the browser already guessed a somewhat compatible encoding, and is an ugly hack for hosting services where you can't influence the header.

      But if you're using CGI anyway, you can just as well use the right solution, not an ugly hack.