Re: HTML::Tree, Unicode, and utf-8
Moshe Kaminsky <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.lwp |
|---|---|
| Message-ID | <[email protected]> |
I used to have problems with this, which appeared to have been solved in a later version of HTML::Tree. Try using encode_utf8($string) (from the Encode module) instead of $string Moshe * Terrence Brannon <[email protected]> [17/11/05 21:06]: > I would like to know how to place Unicode character sequences in an HTML > file whose charset is utf-8. The plain perl program below works fine for > this purpose, but I don't know what to do to get the HTML::TreeBuilder > version to work. > > Also: I am not sure if this will remain the official support channel for > HTML::Tree now that it has changed hands, so I am cc'ing the new maintainer > as well. > > # Working Program > > use strict; > #use utf8; > > my $string = "m\x{c3}\x{b8}\x{c3}\x{b8}se"; > > open O, '>moose.html' or die $!; > > print O <<"EOHTML"; > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> > </head> > <body> > $string > </body> > </html> > EOHTML > > # Fails to preserve unicode characters > > use strict; > use HTML::TreeBuilder; > > > my $string = "m\x{c3}\x{b8}\x{c3}\x{b8}se"; > > open O, '>tbmoose.html' or die $!; > > my $tree = HTML::TreeBuilder->new_from_content(<<"EOHTML"); > <html> > <head> > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> > </head> > <body> > > </body> > </html> > EOHTML > > my $body = $tree->look_down('_tag' => 'body'); > $body->push_content($string); > > print O $tree->as_HTML;
signature.asc
(application/pgp-signature, 198 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2-ecc0.1.6 (GNU/Linux) iD8DBQFDfN9kkBjmVsKMBeMRAsUGAKCgKGd36w7afBAV5bycMqI2xALD2gCgk+EV 9aQz/H86SPecyLJAP8Vwjs8= =vRAv -----END PGP SIGNATURE-----