Adrian
Adrian

Reputation: 53

perl cgi print header charset not work

I have a perl cgi program which output to a simple html form for user data input. The form is in chinese big5 charset

When opened the cgi script, I have to manual switch web browser charset encoding to big5.

I searched on google and I found a method to set charset. Then

original code

$q = new CGI;
print $q->header;

to new code

$q = new CGI;
print $q->header(-charset=>'big5');

However, it just output a blank html.

Upvotes: 1

Views: 904

Answers (3)

Dr.Avalanche
Dr.Avalanche

Reputation: 1996

You're printing headers, but no content, so the page will be blank. Use Firebug or similar to verify the response from the server.

Upvotes: 0

user2676655
user2676655

Reputation: 44

If those are the only two lines, then it's probably working.

Run the cgi from command line and you should see:

Content-Type: text/html; charset=big5

Upvotes: 1

user1558455
user1558455

Reputation:

This works for me:

use CGI;
my $q = CGI->new();
print $q->header(-charset => 'big5');
print '簡體字';

When i try it, it will be showed correctly. (Make sure, that your script is also saved in big5).

Upvotes: 3

Related Questions