For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > utf-8 header in CGI script









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author utf-8 header in CGI script
Jan Eden

2004-05-22, 11:32 am

Hi all,

I followed the recent thread on Unicode output, but I still have a question=
=2E When writing static XHTML files, I use

<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8" />

to indicate the character set. This works fine.

But when generating output, this method does not work. I have to use:

print $q->header(-type=3D>'text/html', -charset=3D>'utf-8');

print qq{<html>
<head>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3Dutf-8" />
[...]

Using

print $q->header;

without parameters results in incorrect display of 8-bit characters.

AFAIK, my ISP's apache webserver serves HTML files with the standard text/h=
tml header, i.e. without a charset specified. Why do I have to specify the =
charset in the header when generating pages with Perl/CGI? Why doesn't the =
meta tag suffice?

Thanks,

Jan
--=20
Common sense is what tells you that the world is flat.
Shaun Fryer

2004-05-22, 11:32 am

I don't have any direct experience with utf-8 headers, but I have
noticed that some browsers (namely IE) ignore http headers and/or
meta-tags at will.

An example off the top of my head is when printing images from a
cgi. Unless the cgi ends in something like .jpg or .gif, the browser
will just dump the binary data on-screen or not at all. I've used a
work around successfully by simply tacking on a GET string like
my.cgi?some.gif. IIRC the same happens with .txt files that contain
unescaped HTML. Regardless of headers, the HTML will be interpreted
as HTML.

Anyway the point of this being that interpretation of headers, meta-
tags and even page content is browser dependant. It's got
little/nothing to do with the httpd (barring unusual configurations).
Normally you just have to find a solution by trial and error to code
around the problem. If having portable code means adding an extra
line or two ... c'est la vie. There's usually not much else you can
do.

-Shaun

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com