我正在解析一些html:
use Modern::Perl;
use Mojo::DOM;
use strict;
use DBI;
use DBD::mysql;
use utf8::all;
my $dbh = DBI->connect("DBI:mysql:db_name", "db_username") or die ("Error:
$DBI::errstr");
my $html = do { local $/; <DATA> };
my $dom = Mojo::DOM->new($html);
my $text = $dom->all_text;
say $text;
my ($var1, $var2, $var3); #normally have values assigned, but not relevant to example
#write $text to MySQL database
$dbh->do("INSERT INTO table_name VALUES (?,?,?,?)",
undef,
$var1, $var2, $var3, $text
);
__DATA__
<div class="field-content"><p> </p>
<p>Here is some data with a trademark html symbol SUPER PRODUCT™, featuring curved
LCD screen.</p></div>
将解析后的文本写入标准输出会产生以下结果:
Here is some data with a trademark html symbol SUPER PRODUCT™, featuring curved LCD
screen.
一切都很好,这是写入 MySQL 的。但是,在 MySQL 中以及从 MySQL 中提取数据时,我们会得到:
Here is some data with a trademark html symbol SUPER PRODUCTâ„¢, featuring curved LCD
screen.
我怀疑这与 Unicode 有关,所以尝试更改 MySQL 状态设置,但仍然没有乐趣。如何正确解决这个问题?