POST php with charset utf-8

0

Good morning, after searching extensively for solutions to my problem, trying out various solutions that were suggested in other questions, like this one for example:

link

I'm looking for information from a php POST of a query to the Oracle database, but the output of this information, may contain special characters: in the database is saved as "John" in the post exits "Jo? o."

I would like the tip of the friends for a configuration (ideal that is global php.ini) where you could configure the output php charset. Some settings I've already made:

PHP.ini

default_charset = "utf-8"
internal_encoding = 'utf-8'
output_encoding = 'utf-8'

Index.php

    <meta http-equiv="content-type" content="text/html;charset=UTF-8" />
    <meta charset="utf-8" />
   </head>
    <body>
     <?php
      var_dump($result1);
     ?>

... ["NAME"] = > string (4) "Jo? o" ...

Being in the database is saved correctly:

Connectiontothebank:

$host="10.0.0.2";
$service="//10.0.0.2:1521/orcl";
$conn= new \PDO("oci:host=$host;dbname=$service","USER","senha");

If I give the command below to check the encoding of the string, I get 'ASCII'

echo mb_detect_encoding($result1['NOME']);

I've also tried using the utf8_encode () function; but nothing changes .. :(

If I write other texts in index.php that contain special characters they are displayed normally, so I do not believe there is some config in the editor-level file or meta tag.

Thank you very much in advance.

    
asked by anonymous 10.01.2017 / 13:26

2 answers

1

In your connection code, the charset of the connection was not entered.

Set the connection charset by adding ;charset=utf8 to the end of the connection string, eg

$conn= new \PDO("oci:host=$host;dbname=$service;charset=utf8","USER","s‌​enha");

Check the charset of tables and fields in your database:

  

Are they all UTF-8?

Set header in PHP:

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

Set header in HTML (you already did):

<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<meta charset="utf-8" />
    
10.01.2017 / 14:17
-1

I use some ways, in case one does not work the other try rsrs

  

echo utf8_decode($nome);
  • The other way I use it is like this when it comes from the bank:
  

echo mb_strtoupper($nome,'UTF8');
  • Another is when I connect to the bank:
  

class ConnectionFactory{
    private $ora_user = "login"; 
    private $ora_senha = "senha"; 
    private $ora_bd = "(DESCRIPTION=
                        (ADDRESS_LIST=
                        (ADDRESS=(PROTOCOL=TCP)(HOST=ip-do-server)(PORT=1521))
                        )
                        (CONNECT_DATA=
                        (SERVICE_NAME=servico)
                        )
                        )"; 
    public  function  getConnection(){
            putenv("NLS_LANG=PORTUGUESE_BRAZIL.AL32UTF8") or die("Falha ao inserir a variavel de ambiente");
            $ora_conexao = oci_connect($this->ora_user, $this->ora_senha, $this->ora_bd);
        return $ora_conexao;

    }

    public function closeConnection($connection){
        $ora_conexao = oci_close($connection);

    }


}
  • Or as the colleague Allan Andrade spoke, using the header:
  

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

It worked for me. Hope it helps

    
10.01.2017 / 16:15