cormanaz has asked for the wisdom of the Perl Monks concerning the following question:
Good day bros. I have some URLs and page titles that contain UTF-8 chars (French and Arabix). I am trying to write them to an HTML file like so:
However in the resulting files, the characters are in the windoze charset. On the advice of a post somewhere else, I tried adding binmode(OUT,":utf8"); after the file open, no help. I also tried wrapping the encode statements in encode_entities from HTML::Entities. Also no help. How do I get these chars to output properly?Use Encode; . . . open(OUT,">topurls.htm") or die "Can't open output: $!"; print OUT <<'END_HEADER'; <html> <head> <title>Top URLs</title> <meta http-equiv="Content-Type" content="text/html; ch +arset=utf-8"> </head> <body> <h3>Top URLs</h3> <table cellpadding=10 border=1><tr><th>Link</th><th>Co +unt</th><th>Users</th></tr> END_HEADER foreach my $u (keys %topurls) { my @line; $line[0] = '<a target="_blank" href="'.encode('UTF-8',$u).'">'.enc +ode('UTF-8',$topurls{$u}{title}).'</a>'; $line[1] = $topurls{$u}{count}; $line[2] = $topurls{$u}{users}; print OUT '<tr><td>'.join('</td><td>',@line).'</td></tr>'."\n"; } print OUT '</table></body></html>'; close OUT;
|
---|
Replies are listed 'Best First'. | |
---|---|
SOLVED Re: Writing HTML file with UTF-8 chars
by cormanaz (Deacon) on Apr 27, 2013 at 18:33 UTC | |
by 2teez (Vicar) on Apr 27, 2013 at 18:57 UTC | |
Re: Writing HTML file with UTF-8 chars
by choroba (Cardinal) on Apr 27, 2013 at 16:19 UTC | |
by cormanaz (Deacon) on Apr 27, 2013 at 16:25 UTC | |
by chromatic (Archbishop) on Apr 27, 2013 at 16:33 UTC | |
by choroba (Cardinal) on Apr 27, 2013 at 16:55 UTC |
Back to
Seekers of Perl Wisdom