Problem accentuation PHP and MySQL [duplicate]

-2

I have a question regarding accentuation, specifically the return of% with%. My bank has collation Ç , I'm using HTML tags:

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 <html lang="pt-BR">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

And in the bank the latin1_swedish_ci and accents are correctly registered, as below:

Butatthetimeofdisplayingthedata,itlookslikethis:

PHP displays this way (in the 3rd line I did a test that did not work):

foreach ($saidas as $saida) { ?>
   <tr>
   <td><?php echo $saida['reserva'] ?></td>
   <td><?php echo $saida['motorista'] ?></td>
   <td><?php header("Content-Type: text/html; charset=ISO-8859-1", true); echo $saida['setor'] ?></td>
   <td><?php echo $saida['email'] ?></td>
   <td><?php echo $saida['veiculo'] ?></td>
   <td><?php echo $saida['destino'] ?></td>
   <td><?php echo $saida['data'] ?></td>
   <td><?php echo $saida['saida'] ?></td>
   <td><?php echo $saida['retorno'] ?></td>
   <td><?php echo $saida['retorno_real'] ?></td>
   </tr>

<?

Any suggestions?

    
asked by anonymous 07.12.2015 / 13:09

2 answers

3

I solved it like this:

<td><?php echo utf8_decode($saida['setor']) ?></td>
    
07.12.2015 / 13:38
2

If you are connecting to MySQL via the terminal (with the famous mysql command -u nomedousario -p), make sure this connection is also with the correct character-set.

It turns out that many times (this happened to me) your PHP connection to MySQL may be perfect, all with the same encoding, character set and collation, all perfect. But when you check through the terminal you see the broken characters.

Yes, it gives the impression that PHP and MySQL are wrong and the terminal is right, but not necessarily.

To test, connect to MySQL through the terminal with the following command: mysql -u username -p -default-character-set = charset

Where: username is your username and charset is the charset you are trying to configure the server for.

Suppose your user is root you left PHP, HTML and MYSQL configured to run in UTF-8. Your connection should look something like this:

mysql -u root -p --default-character-set=utf8
Ou então para o famoso: ISO-8859-1

mysql -u root -p --default-character-set = latin1 If your connection occurs with your desired charset and the data has been corrupted, then it means that they have been inserted by another charset. Ha! We got the error!

So if you change in the nail (via update) the data (Now your thread is in the right charset) will be correct in the terminal. If everything went right while updating your PHP page you will notice that the characters also stayed right there.

To set the default-character-set in MYSQL so that you do not need to be forced through the terminal you just have to specify it in your MySQL configuration file (my.cnf or my.ini).

 [mysql]
  default-character-set=seucharset
    
07.12.2015 / 13:17