This is a good question and the answer is non-trivial to comprehend.

I recommend taking a look at this page, which is a mirror of a (now-defunct but highly useful) original for background: http://niwo.mnsys.org/saved/~flavell/charset/form-i18n.html

In short, you never *really* know exactly what you're getting back from a browser, and the very best belt-and-suspenders thing you can do is to have a "magic cookie" hidden form field on each form that contains a smattering of odd characters with an unambiguous representation in each encoding you suspect. That is, you put a bunch of CJK and other stuff, output as HTML entities, into your form field, and you use a heuristic based upon what the browser sends back to determine what encoding the browser has decided to use.

You can also look at Encode::Guess, which makes some informed guesses based on the content, but doesn't require making the round-trip the way the form field technique does.

But what most people do, and what's probably most tractable unless you're trying to solve a problem for a large, diverse user-base, is to figure out what the top 3-4 user-agents you serve do, and just bank on that...


In reply to Re: UTF-8 or iso-8859-1 input to CGI.pm by rlucas
in thread UTF-8 or iso-8859-1 input to CGI.pm by thedi

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.