Joao Victor
Joao Victor

Reputation: 1171

uft8_Encode or utf8_decode for accented characters in my mysql column

I'm getting some records in my mysql database, and some have accented characters in their texts.

For example:

"PONTO : 09867, TABULETA : 08112, POSIÇÃO : 1 , MOTIVO : DIVULGACAO FADE/FAL"

Since i have to break this string down, i use this:

$var = explode(", ", "PONTO : 09867, TABULETA : 08112, POSIÇÃO : 1 , MOTIVO : DIVULGACAO FADE/FAL"

I've tried this:

$x = utf8_encode($var[2]); - where the accented charater is

But it keeps getting me something like this:

POSIÃÂÃÂO : 2

Or

POSI?O : 2

I've tried decode as well, but still with no success. Is there any solution?

Upvotes: 0

Views: 375

Answers (2)

blue
blue

Reputation: 1949

Set connection encoding to UTF-8:

SET NAMES UTF8;

Take a look also at set charset.

Update:

It turns out it is a php issue, so one might take a look at Character sets

Upvotes: 2

Uriziel
Uriziel

Reputation: 177

If I understand correctly the query result is ok just explode cuts the result in wrong places, thats because explode is not a multibyte function. You will have to do it with preg_split

$var= preg_split("/[\,]+/", "PONTO : 09867, TABULETA : 08112, POSIÇÃO : 1 , MOTIVO : DIVULGACAO FADE/FAL");

As we can see it is working correctly: http://screencast.com/t/hW7Bo9vB

Upvotes: 1

Related Questions