Help with accents

Asked

Viewed 288 times

0

Tó with a problem to solve problems and accents in PHP pages and need a light.

To solve the field names problem I used Cód. below in my file funcoes.php and in all pages I put include 'Adm/funcoes.php';

File functions.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;
}

?>

Up to there solves problems with field names for example Address was coming as Address.

There I have the queries in mysqli that keeps coming with the characters instead of the accents

File consult_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 take out the function in the functions.php file the return of the queries comes correctly if I leave the two active the return of the query back to bring the names with characters as for example HEALTHY PAUL.

How can I fix this?

  • you do not prefer to work with UTF-8 ??

  • I tried with UTF-8 and it didn’t work either

  • put your code to understand better !!

  • Is Collection in your database as? Example: uft8mb4_unicode_ci

  • Ramos: That’s right and the tables utf8_general_ci Thiago: I’ll edit the question and put a Cód of an example page.

  • download the Notepad++ and convert the files to utf-8 without GOOD (utf-8 without GOOD) do this with all the files, in Notepad++ go on format > convert to UTF-8 NO GOOD tds files must be equal

  • I’ve done it before and it didn’t work

  • after converting the files php you changed from charset=ISO-8859-1" to charset="UTF-8" too ? because if only convert the file formatting and do not change the encoding look like this, remembering that "ALL" the project files must be in the same encoding

  • all these includes you gave

  • Yes I changed everything from ISO-8859-1 to utf-8 the query return comes correctly but the names of the fields in the form come with the example characters Rela and the correct is Relation

  • Weird, you downloaded the nodpadd++ ? it is not the same as notpad, it has this opiation of altering the encoding of the file that is not the same as the charset, whenever it happens with me I do it and the right, so in your case I fear that I should create the files again, beware if using any netbeans example IDE, Dream Weaver they usually define

  • Form files created in phpeditor that does not have the format option. Then I downloaded the Notepad++ v7.5.5 and opened the files I made a change and I switched to utf-8 encoding without good and I’m not sure I’ll have to recreate all the files?

Show 7 more comments

1 answer

1

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

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

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

By following these checks, you will never again have problems with any accent.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.