ganjan
ganjan

Reputation: 7596

get � when for special characters using gettext and smarty

I am using $encoding = 'utf-8'; in gettext and in my html 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?

Upvotes: 3

Views: 1656

Answers (2)

Julio
Julio

Reputation: 1943

You need to set this

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

Otherwise you will get the � character

Upvotes: 4

Artefacto
Artefacto

Reputation: 97835

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)

Upvotes: 4

Related Questions