Loading ...
Sorry, an error occurred while loading the content.

2311Output character encoding

Expand Messages
  • Arnon Weinberg
    Jun 5 2:02 AM
      How can I set the output character encoding of Apache::ASP output?

      Regular perl/CGI output defaults to ISO-8859-1 encoding, and may be
      easily modified using the use open prama or binmode() function. Here is
      my test script:

      # Latin-1.cgi: ##############

      #use open ( ":utf8", ":std" );
      #binmode ( STDOUT, ":encoding(ISO-8859-1)" );

      use CGI;
      print CGI::header();

      use Encode;

      print Encode::decode('ISO-8859-1',"\xE2"),
      Encode::decode('UTF-8',Encode::encode('UTF-8',"\xE2")),
      "\x{00E2}",
      chr(0x00E2);

      #############################

      >perl Latin-1.cgi
      Content-Type: text/html; charset=ISO-8859-1

      ââââ
      >perl Latin-1.cgi | tail -1 | hexdump
      0000000 e2e2 e2e2
      0000004

      This script correctly produces ISO-8859-1 encoded output.

      However, Apache::ASP appears to default to some strange mix of
      ISO-8859-1 and UTF-8 that I can't make sense of.
      Additionally, the use open pragma and binmode() function appear to have
      no effect:

      # Latin-1.rasp: #############

      <%
      #use open ( ":utf8", ":std" );
      #binmode ( STDOUT, ":encoding(ISO-8859-1)" );

      $::Response->{Charset} = "ISO-8859-1";

      use Encode;

      print Encode::decode('ISO-8859-1',"\xE2"),
      Encode::decode('UTF-8',Encode::encode('UTF-8',"\xE2")),
      "\x{00E2}",
      chr(0x00E2);
      %>

      #############################

      >asp-perl Latin-1.rasp
      Content-Type: text/html; charset=ISO-8859-1
      Content-Length: 6
      Cache-Control: private

      ââââ
      >asp-perl Latin-1.rasp | tail -1 | hexdump
      0000000 a2c3 a2c3 e2e2
      0000006

      For some reason, the first 2 test characters are UTF-8 encoded, and the
      last 2 are ISO-8859-1 encoded.
      How can I get the same results as the CGI script above?


      --
      -------------------------------------------------------------------------------
      Arnon Weinberg
      www.back2front.ca


      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Show all 9 messages in this topic