Problems with PHP encoding in UTF-8 [duplicate]

3

None of the solutions suggested in various forums, websites and the like worked. I ran several tests and none of them worked and so I came here.

The website where the error occurs is this: link

It was not developed by me, a client of mine requested that I fix this problem for him.

All special characters are always replaced by Ã. I tried to change the encoding to ISO and the error remained, tried to change the encoding in the database, force UTF-8 on header , set javascript to interpret as UTF-8 and none of that worked. p>

The connection to the database is as follows:

<?php
$bd_host = "localhost";
$bd_user = "simulado_bd"; // Usuário do Banco de Dados
$bd_pass = "********"; // Senha do Bando de Dados
$bd_bd = "simulado_bd"; // Nome do Banco de Dados
$conectar = mysql_connect($bd_host, $bd_user, $bd_pass) or die (mysql_error());
mysql_select_db($bd_bd, $conectar);
mysql_query('SET CHARACTER SET utf8');
    
asked by anonymous 29.10.2015 / 17:37

3 answers

4

I've had the same problem. I was able to resolve this:

mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');

Put all lines after your connection, it will probably work!

    
29.10.2015 / 19:25
4

Verify that the file is converted to UTF-8 without BOM / UTF-8 sem BOM . Verify that the MySQL database is as UTF_8 .

If both are correct, do the following with your pages in php

header('Content-Type: text/html; charset=utf-8');<meta charset="utf-8" /> 

and not html

<meta charset="utf-8" /> 
    
29.10.2015 / 19:04
4

Maybe it helps someone, I was having trouble with AJAX.

I was using it in php:

*header('Content-Type: text/html; charset=utf-8');* 

I've changed to:

*header('Content-type: text/html; charset=iso-8859-1');*
    
17.07.2017 / 11:11