0
I need to assemble a JSON
, in the PHP
, to return data to Angularjs, but one of the Object data from JSON
is coming with the letter "á" with another character. How can I correct this?
NOTE: The name is accented in the BD as it was inserted into the BD with accent. BD is set to utf8-bin.
My php:
<?php
ini_set('display_errors', true);
error_reporting(E_ALL);
header('Access-Control-Allow-Origin: *');
header('Content-Type: text/html; charset=utf-8');
include_once("conPDO.php");
$pdo = conectar();
$idUsuario = $_GET['idUsuario'];
$pegaUsuario=$pdo->prepare("SELECT * FROM usuarios WHERE idUsuario=:idUsuario");
$pegaUsuario->bindValue(":idUsuario", $idUsuario);
$pegaUsuario->execute();
$return = array();
while ($linha=$pegaUsuario->fetch(PDO::FETCH_ASSOC)) {
array_push($return, $linha);
}
print_r($return[0]);
//echo json_encode($return[0]);
?>
And see how the json Object appears on the console, see the name.
Possible duplicate of Doubt with charset=iso-8859-1 and utf8. Try everything from the answer http://answall.com/a/43205/3635, including the
exec('SET CHARACTER SET utf8');
– Guilherme Nascimento
Already solved the problem?
– Julyano Felipe
@Guilhermenascimento, I’m using utf8-bin in the database, so the database accepts accented letters. I just don’t understand why this json, "distorts" the letter "á".
– GustavoSevero
Why did the
$pdo->exec('SET CHARACTER SET utf8');
like I said before.– Guilherme Nascimento