How to change charset=ISO-8859-1 to charset=UTF8? Rocky 9.1 server
Hi ! Everyone, I am back here to ask environmental issue.
When I ran the following CGI.pm testing script before placing at /var/www/cgi-bin, but it is still at /home/mkido/bin. Perl script ran successfully at the Terminal, and replied back the OUTPUT below there.
Perl Script, check.pl
my $q = CGI->new;
mkido@localhost$check.pl [Enter to run it.]
Content-Type: text/html; charset=ISO-8859-1
This output result evoked my recognition. Is this Rocky 9.1 Web Server running to provide charset=ISO-8859-1 ?? I want to set all replies from the Server to charset=UTF-8. The httpd.conf is already set to charset=UTF-8. Is there any other setting adjustment somewhere in environmental configuration on my server to change from charset=ISO-8859-1 to charset=UTF-8 ?? Thanks, thanks.
I would assume that the Perl CGI module is so old it defaults to latin-1. A quick glance at the docs confirms this:
"The -charset parameter can be used to control the character set sent to the browser. If not provided, defaults to ISO-8859-1."
So you'll need to tell CGI.pm explicitly to use utf8 via $cgi->header(-charset => 'utf-8') AND make sure the content is correctly encoded.
That being said, I would not use plain CGI.pm but look into Plack/PSGI instead (which has a CGI compat mode).
Thank you, domm, I can manage to change $cgi->header(=>'utf-8'). It worked.
By the way, I have a tiny question related with character encoding. To clearly present my question, I want to post screenshot (png or jpg) here. May I use graphics file attachment here?
Sorry there is a typo.
$cgi->header(-character=>'utf-8'). It worked.
Yes, at least there are multiple posts using images etc