[英]how to convert HTML file to UTF-8 using Perl
我在下面的位置有一個HTML文件
我想將上面的HTML文件轉換為UTF-8編碼格式,我在Perl中嘗試了以下方法
use strict;
use Cwd;
use HTML::Entities;
use HTML::Entities::Numbered;
use HTML::Strip;
use Encode;
use utf8;
my $parentPath = $ARGV[0];
#my $parentPath = getcwd()."/".$epubHTMLName;
opendir(FOLDER,$parentPath) || die "No such directory !";
my @readDir = readdir(FOLDER);
close FOLDER;
foreach(@readDir){
#print $_."\n";
my $fold = $_;
my $match = lc($fold);
my @dotcount;
while ($match=~m/(html)/gi){
push(@dotcount,$1);
}
my $totalcount = @dotcount+0;
print $fold."\n";
if ($fold ne "." && $fold ne ".." && $totalcount eq 1) {
my $input = $parentPath."\\".$fold;
my $output = getcwd()."/Output/".$fold;
open(HTMLFILE, $input) || die "Check your File !";
local $/ = undef;
my $htmlcontent = <HTMLFILE>;
$htmlcontent = decode_entities($htmlcontent);
$htmlcontent =~s/\x{feff}//g;
close HTMLFILE;
open my $out, '>:encoding(UTF-8)', $output;
print {$out} $htmlcontent;
close $out;
}
}
通過上述方法轉換后,我可以在Google Chrome
以UTF-8格式看到,但我無法在FireFox
看到它。 因此,需要一種在Chrome
和Firefox
以UTF-8查看HTML文件的方法。
輸出文件供您參考: http : //jmp.sh/tp5QHwG
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.