in reply to Re: Reading in utf-8 txt file gives garbled data when printed as part of utf-8 html...
in thread Reading in utf-8 txt file gives garbled data when printed as part of utf-8 html...
gives me:open(FILE, '<', 'file.txt'); # binmode(FILE,":utf8"); my $content; { local $/; $content = <FILE>; } close(FILE); # binmode(STDOUT,":utf8"); use Data::Dumper; use HTML::Entities; print "Content-Type: text/html; encoding=utf-8\n\n"; local $Data::Dumper::Useqq = 1; print '<pre>'; print encode_entities(Dumper($content)); print '</pre>'; print $content;
(when viewed in encoding=utf-8)$VAR1 = "f\303\266\303\266\n"; föö
gave me:open(FILE, '<', 'file.txt'); binmode(FILE,":utf8"); my $content; { local $/; $content = <FILE>; } close(FILE); binmode(STDOUT,":utf8"); use Data::Dumper; use HTML::Entities; print "Content-Type: text/html; encoding=utf-8\n\n"; local $Data::Dumper::Useqq = 1; print '<pre>'; print encode_entities(Dumper($content)); print '</pre>'; print $content;
(but I needed to set encoding=utf-8 manually on this one, was western before..)$VAR1 = "f\x{f6}\x{f6}\n"; föö
open(FILE,"<:utf8", "$file"); binmode(FILE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Reading in utf-8 txt file gives garbled data when printed as part of utf-8 html...
by ikegami (Patriarch) on Aug 27, 2007 at 23:35 UTC | |
by isync (Hermit) on Aug 28, 2007 at 09:54 UTC | |
by Anonymous Monk on Apr 21, 2009 at 23:49 UTC | |
by ikegami (Patriarch) on Apr 22, 2009 at 00:19 UTC |