我想知道为什么json_encode回显“null”而我用西班牙语字符作为“ñ”
$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));
答案 0 :(得分:1)
$lamarcavino
在utf8_decode()
之后是ISO 8859-1,因为utf8_decode()
converts from UTF-8 to ISO 8859-1。
json_encode()
does only support UTF-8以及ISO 8859-1中的某些较高字符在UTF-8中无效。