CGI character set display

Moderator: cah

Post Reply
cah
General of the Army / Fleet Admiral / General of the Air Force
General of the Army / Fleet Admiral / General of the Air Force
Posts: 1342
Joined: Sun Aug 17, 2008 5:05 am

CGI character set display

Post by cah »

For some of my CGIs, I have to enter Chinese characters to them.
After migrating to RHEL 7, I started using UTF8 over Big5 due to the higher acceptance of UTF8. Also, Apache is sort of forcing to use UTF8 for uniform behavior.

Here is an example of entering Chinese character and Big5 shows garbage codes:

Entering:

Code: Select all

 For 蕭家緯(Chia-Wei Hsiao)
entering grade 一年級(1st Grade)
Registration Fee:
    $35.00
Tuition:
    $470.00
Books / Material:
    $20.00
PVA Annual Membership:
    $15.00
CCCA Annual Membership:
    $20.00
Grand Total:
    $560.00
but got

Code: Select all

For �剖振蝺�(Chia-Wei Hsiao) entering grade 銝�撟渡�(1st Grade) Registration
Fee: $35.00 Tuition: $470.00 Books / Material: $20.00 PVA Annual Membership:
$15.00 CCCA Annual Membership: $20.00 Grand Total: $560.00 
The way to correct this is to change the code from

Code: Select all

print $cgi->header(-charset  => 'Big5');
to:

Code: Select all

print $cgi->header(-charset  => 'UTF8');
After making the change, the new output becomes readable:

Code: Select all

For 蕭家緯(Chia-Wei Hsiao) entering grade 一年級(1st Grade) Registration Fee: $35.00 Tuition: $470.00 Books / Material: $20.00 PVA Annual Membership: $15.00 CCCA Annual Membership: $20.00 Grand Total: $560.00 
and data can be written to database (MySQL) then.
CAH, The Great
Post Reply