Mikolaj
Mikolaj

Reputation: 708

PHP: Special chars not shown correctly

I have a value (name) stored in pg database, the value is Müller. However, for example when I var_dump('Müller'); I get output : MÃ1/4ller.

I've tried setting header('Content-Type: text/html; charset=UTF-8'); and no go.

Funny thing is, I'm not getting this issue on client side, name is displaying correctly, but on server end, when breaking up the first three letters of the name instead of getting:

array(3) {
    [0] =>
    string(1) "M"
    [1] =>
    string(1) "ü"
    [2] =>
    string(1) "l"
}

I get:

array(3) {
    [0] =>
    string(1) "M"
    [1] =>
    string(1) "Ã"
    [2] =>
    string(1) "1/4"
}

I figure that since the database is storing the value correctly, that must be a php thing, but haven't been able to figure it out after quite a bit of googling, so maybe I am not searching for the correct query?

Upvotes: 0

Views: 56

Answers (1)

Loïc
Loïc

Reputation: 11942

It depends on your schema configuration.

Try utf8_decode() before dumping with PHP. http://php.net/manual/fr/function.utf8-decode.php

Alternatively you can use utf8_encode(), to encode a string back to utf8

Upvotes: 1

Related Questions