Help with accents [duplicate]

0

I have a problem to solve problems and accents in PHP pages and I need a light.

To solve the problem of field field names I have used code no. below in my file funcoes.php and in all the pages I put include 'adm / funcoes.php';

File funcoes.php

  <?php

@header( "Content-Type: text/html; charset=ISO-8859-1", true );

function formata_dinheiro($valor) {
    $valor = number_format($valor, 2, ',', '.');
    return "R$ " . $valor;
}
function dinheiro_bd($valor) {
    $valor = str_replace(",", ".", $valor); 
    return $valor;
}
function dinheiro_br($valor) {
    $valor = number_format($valor, 2, ',', '.');
    return $valor;
}
function grafico_dinheiro($valor) {
    $valor = number_format($valor, 2, '.', '');
    return $valor;
}
function mostraMes($m) {
    switch ($m) {
        case 01: case 1: $mes = "Janeiro";
            break;
        case 02: case 2: $mes = "Fevereiro";
            break;
        case 03: case 3: $mes = "Mar&ccedil;o";
            break;
        case 04: case 4: $mes = "Abril";
            break;
        case 05: case 5: $mes = "Maio";
            break;
        case 06: case 6: $mes = "Junho";
            break;
        case 07: case 7: $mes = "Julho";
            break;
        case 08: case 8: $mes = "Agosto";
            break;
        case 09: case 9: $mes = "Setembro";
            break;
        case 10: $mes = "Outubro";
            break;
        case 11: $mes = "Novembro";
            break;
        case 12: $mes = "Dezembro";
            break;
    }
    return $mes;
}

?>

Until then it solves the problems with the names of the fields for example Address was coming like Direction.

I have queries in mysqli that continue to come with the characters instead of the accents

File query_clients.php

<?php
session_start();
$nivel = 1;
set_time_limit(0);
date_default_timezone_set('America/Sao_Paulo');
include 'adm/config.php';
include 'adm/functions.php';
include 'adm/menu.php';
include("adm/seguro.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title id='titulo'>Estoque<?php echo $lc_titulo?></title>
<meta name="LANGUAGE" content="Portuguese" />
<meta name="AUDIENCE" content="all" />
<meta name="RATING" content="GENERAL" />
<body background="fundo.jpg" bgproperties="fixed">
<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/png" href="img/fish.png" />
<link href="menu.css" rel="stylesheet" type="text/css" />
<script language="javascript" src="js/scripts.js"></script>
<script language="javascript" src="js/jquery.js"></script>
<script language="javascript" src="js/mascaras.js"></script>
</head>

<tr>
<table cellpadding="1" cellspacing="10"  width="900" align="center" style="background-color:#033">
<td colspan="1" style="background-color:#005B5B;">
<h2 style="color:#FFF; margin:5px">Estoque - <?php echo $lc_titulo?></h2>
</td>
<td colspan="2" align="right" style="background-color:#005B5B;">
<a style="color:#FFF" href="?mes=<?php echo date('m')?>&ano=<?php echo date('Y')?>">Hoje:<strong> <?php echo date('d')?> de <?php echo mostraMes(date('m'))?> de <?php echo date('Y')?></strong></a>&nbsp;
</td>
</tr>

<table cellpadding="5" cellspacing="0" width="900" align="center">
<tr>
<td align="right">
<hr size="1" />
<h2><p align="center"><font color="#008000">Relação de Clientes</font></p></h2>
</td>
</tr>
</table>
</body>
</html>

<head>
    <?php
         include "js/jquery.dataTables.php";?>
        <script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
    $('#example').dataTable( {
        "bPaginate": false,
        "bLengthChange": false,
        "bFilter": true,
        "bSort": false,
        "bInfo": false,
        "bAutoWidth": false } );
} );
        </script>
         <link href="css/demo_table.css" rel="stylesheet" type="text/css">
               </head>
<?php

      $sel = mysqli_query ($conexao,"SELECT * FROM clientes ORDER BY nome asc");
mysqli_set_charset($conexao, 'ISO-8859-1');
         $c = 1;

?>
              <table width="100%" border="0" cellpadding="2" cellspacing="2" class="display" id="example" align="center">
            <thead>
        <tr class="fonte_titulos">
   <th  bgcolor="#F4EADC">Nome</th>
   <th  bgcolor="#F4EADC">Fantasia</th>
   <th  bgcolor="#F4EADC">Contato</th>
   <th  bgcolor="#F4EADC">Fone</th>
   <th  bgcolor="#F4EADC">Celular</th>
   <th  bgcolor="#F4EADC">Email</th>
   <th  bgcolor="#F4EADC">CNPJ</th>
   <th  bgcolor="#F4EADC">Insc. Estadual</th>
   <th  bgcolor="#F4EADC">Endereço</th>
   <th  bgcolor="#F4EADC">CEP</th>
   <th  bgcolor="#F4EADC">Bairro</th>
   <th  bgcolor="#F4EADC">Cidade</th>
   <th  bgcolor="#F4EADC">Estado</th>
   <th  bgcolor="#F4EADC">NF</th>
   <th  bgcolor="#F4EADC">Desconto</th>
   <th  bgcolor="#F4EADC">Data</th>
   <th  bgcolor="#F4EADC">Obs</th>
   <th  bgcolor="#F4EADC">ID</th>

    </thead>
    <tbody>
    <?php
        while ($dados = mysqli_fetch_array($sel))
        {
 if (($c % 2) == 1){ $fundo="#F1F1F1"; }else{ $fundo="#E0E0E0"; }

        $nome         = $dados["nome"];
        $fantasia     = $dados["fantasia"];
        $contato      = $dados["contato"];
        $fone         = $dados["fone"];
        $celular      = $dados["celular"];
        $email        = $dados["email"];
        $cnpj         = $dados["cnpj"];
        $estadual     = $dados["estadual"];
        $endereco     = $dados["endereco"];
        $cep          = $dados["cep"];
        $bairro       = $dados["bairro"];
        $cidade       = $dados["cidade"];
        $estado       = $dados["estado"];
        $nf           = $dados["nf"];
        $desconto     = $dados["desconto"];
        $data2        = $dados["data2"];
        $obs          = $dados["obs"];
        $id           = $dados["id"];

  echo "<tr bgcolor =\"$fundo\" class=\"fonte_desc\"><td align=\"center\" width=\"590\">
       $nome</td><td align='center'>".($fantasia)."</td><td align='center'>$contato"."</td><td align='center'>$fone"."</td><td align='center'>$celular"."</td><td align='center'>$email"."</td><td align='center'>$cnpj"."</td><td align='center'>$estadual"."</td><td align='center'>$endereco"."</td><td align='center'>$cep"."</td><td align='center'>$bairro"."</td><td align='center'>$cidade"."</td><td align='center'>$estado"."</td><td align='center'>$nf"."</td><td align='center'>$desconto"."</td><td align='center'>$data2"."</td><td align='center'>$obs"."</td><td align='center'>$id
        ";
    $c++;   }
        ?>
</table>
          </div>
   <p align="center"> </p>
 <?php include "rodape.php"; // fim?>
   </p>
    </body>
</html>

If I throw the function in the file functions.php the return of the queries comes correctly if I leave the two assets the return of the query returns to bring the names with characters like for example PAUL.

How can I fix this?

    
asked by anonymous 13.03.2018 / 20:23

1 answer

1
  • Check the charset that is configured in the database table. Must be Latin-1 or ISO-8859-1;

  • Check the charset of the connection between PHP and the database. It should also be Latin-1;

  • Check the charset configured in your editor / IDE. It should also be Latin-1;

  • Following these checks, you'll never have trouble with any accents.

        
    13.03.2018 / 23:02