Reputation: 11
i want to know why json_encode echo "null" and i use spanish characters as "ñ"
$link=mysql_connect("localhost","josilandia","*****");
mysql_select_db("critica",$link);
mysql_query("SET NAMES utf8");
$region="Mosel-Saar-Ruwer";
$resultado=mysql_query("SELECT marcavino,comentario,estrellas FROM recomendacion2
WHERE region='$region'");
$recomendacion=array();
while ($row = mysql_fetch_assoc($resultado)) {
$lamarcavino =utf8_decode($row['marcavino']);
$elcomentario =utf8_decode($row['comentario']);
$laestrella = $row['estrellas'];
$arr=array('marcavino'=>"$lamarcavino",'comentario'=>"$elcomentario",'estrellas'=>"$laestrella");
$recomendacion[]= $arr;
print(json_encode($recomendacion));
Upvotes: 0
Views: 2954
Reputation: 33697
$lamarcavino
is ISO 8859-1 after the utf8_decode()
, because utf8_decode()
converts from UTF-8 to ISO 8859-1.
json_encode()
does only support UTF-8 and some of the higher characters in ISO 8859-1 are invalid in UTF-8.
Upvotes: 1