开发者

get � when for special characters using gettext and smarty

开发者 https://www.devze.com 2023-01-13 01:54 出处:网络
I am using $encoding = \'utf-8\'; in gettext and in my ht开发者_C百科ml code i have set <meta charset=\"utf-8\">. I have also set utf-8 in my .po files, but I still get � when I write æøå! W

I am using $encoding = 'utf-8'; in gettext and in my ht开发者_C百科ml code i have set <meta charset="utf-8">. I have also set utf-8 in my .po files, but I still get � when I write æøå! What can be wrong?


Let's see how the values you mention are at the byte level.

I copied the æøå from your question and � from your title. The reason for � is that I had to use a Windows console application to fetch the title of your question and its codepage was Windows 1252 (copying from the browser gave me Unicode Character 'REPLACEMENT CHARACTER' (U+FFFD)).

In a script encoded in UTF-8, this gives:

<?php
$s = 'æøå';
$s2 = '�';

echo "s iso-8859-1 ", @reset(unpack("H*", mb_convert_encoding($s, "ISO-8859-1", "UTF-8"))), "\n";
echo "s2 win-1252  ", @reset(unpack("H*", mb_convert_encoding($s, "WINDOWS-1252", "UTF-8"))), "\n";
s iso-8859-1 e6f8e5
s2 win-1252  e6f8e5

So the byte representation matches. The problem here is that when you write æøå either:

  • You're writing it in ISO-8859-1, instead of UTF-8. Check your text editor.
  • The value is being converted from UTF-8 to ISO-8859-1 (unlikely)


You need to set this

bind_textdomain_codeset($domain, "UTF-8");

Otherwise you will get the � character

0

精彩评论

暂无评论...
验证码 换一张
取 消