Get when gettext and smarty are used for special characters

I use $encoding = 'utf-8';in gettext, and in my html code I installed <meta charset="utf-8">. I also installed utf-8 in my .po files, but I still get it when I write æøå! What could be wrong?

+3
source share
2 answers

See how the values ​​you specified are at the byte level.

I copied æøåfrom your question and �from your title. The reason for this �is that I had to use the Windows console application to get the title of your question, and its code page is 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 is the same. The problem here is that when you write æøåeither:

  • You write it in ISO-8859-1 instead of UTF-8. Check out your text editor.
  • The value is converted from UTF-8 to ISO-8859-1 (unlikely)
+4
source

You need to install this

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

Otherwise, you get a character

+3
source

Source: https://habr.com/ru/post/1760933/


All Articles