Error characters in utf8

2

I have a website in Portuguese, in which when I change the version of php and something else, when I insert it in the database, it does it badly and when it is recovered it comes out in the following way:

O hotel dispõe de 150 quartos. Todos os quartos têm telefone de ligação directa, acesso

As you can see, these characters: çã are not correct.

The fact is that if I apply to that text a utf8_encode() is as follows:

O hotel dispõe de 150 quartos. Todos os quartos têm telefone de ligação directa, acesso

Keep going the same.

But if I apply a utf8_encode(utf8_decode()) it is correct:

O hotel dispõe de 150 quartos. Todos os quartos têm telefone de ligação directa, acesso

The problem is that there are some cases in which with utf8_encode() goes well and others do not, and also without putting anything appears correct. How can I automatically detect when I should use one or the other?

Currently I have it manually with if - else depending on the id of the page, but every time there is more so I need to automate it

    
asked by 14.06.2017 в 12:06
source

1 answer

-1

What database engine are you using? If you use MySql try adding after declaring the connection to the database mysqli_set_charset ($ link, 'utf8'); or mysql_set_charset ('utf8', $ link), depending on the extension you are using, this will guarantee that in each connection you will store or retrieve the records properly and you can leave the database coding like this: database charset = utf8 and database collation utf8_general_ci

    
answered by 14.06.2017 в 15:26