utf8 encoding in Perl and MySql

前端 未结 4 1905
无人共我
无人共我 2021-02-13 16:57

my database (MySql) has a utf8_general collation. I am accessing data from database and showing a webpage (developed in Perl), it is showing Swedish characters (ä,å,ö) with a di

4条回答
  •  清酒与你
    2021-02-13 17:34

    If each ä/å/ö is being represented in the output by two bytes, then it's also possible that you may be double-encoding the characters. (Given that the question already shows you doing $dbh->{'mysql_enable_utf8'} = 1;, I suspect that this is the most likely case.) Another possibility, given that you're displaying this on a web page, is that the page may not be specifying that the charset is UTF-8 in its and the browser could be guessing incorrectly at the character encoding it uses.

    Take a close look at your webapp framework, templating system, etc. to ensure that the values are only being encoded once between when they're retrieved from the database and when they reach the user's browser. Many frameworks/template engines (such as the combination of Dancer and TT that I normally use) will handle output encoding automatically if you configure them correctly, which means that the data will be double-encoded if it's explicitly encoded prior to being output.

提交回复
热议问题