English 中文(简体)
• 如何去除Perl的CGI违约金果园。
原标题:How to remove CGI default meta charset encoding in Perl?

采用《刑法》

#!/usr/bin/perl

use strict;
use warnings;
use CGI ":all";
use Encode;

my $cgi = new CGI;

$cgi->charset( utf-8 );

print $cgi->header(-type    =>  text/html ,
                   -charset =>  utf-8 );

print $cgi->start_html(-title =>  Test ,
                       -head  => meta({-http_equiv =>  Content-Type ,
                                       -content =>  text/html; charset=utf-8 }));
my $text =  test ; # for now

Encode::from_to($text,  latin1 ,  utf8 );

print $cgi->p($text);
print $cgi->end_html;

我正在取得以下产出:

Content-Type: text/html; charset=utf-8

<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>test</p>
</body>

而我不知道为什么这样,为什么我不知道为什么为什么为什么为什么为什么?

<meta http-equiv=“Content-Type” content=“text/html;charset=iso-8859-1”/>

产出不变,我不知道如何删除。

欢迎所有建议。

最佳回答

添加<条码>-编码参数至<条码>>>>>,从_html开始,不逐手建造元件。 (尽管农研组建议你这样做)。

print $cgi->start_html(-title => "Test", -encoding => "utf-8")
问题回答

最新版本CGI.pm (目前安装了3.52件),你没有必要人工建造<代码><meta>要素。 只有在你称之为<代码>header方法时,你才得提供果园。 该方案:

#!/usr/bin/perl

use strict;
use warnings;
use CGI ":all";
use Encode;

my $cgi = CGI->new;
binmode STDOUT,  :utf8 ;

print $cgi->header(-type =>  text/html ,
                   -charset =>  utf-8 );

print $cgi->start_html(-title =>  Test );
my $text = "x{201c}testx{201d}"; # for now

print $cgi->p($text);
print $cgi->end_html;

给我这一产出:

Content-Type: text/html; charset=utf-8

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<p> test </p>
</body>
</html>

我有一部工作法典。

use CGI qw(:standard);

print header( -type => "text/html; charset= utf-8 ");

print 
    start_html(
        -title =>  Простой пример , 
        -bgcolor => "#cccccc",
        -encoding => "utf-8"
    );




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签