Character encoding error when setting values from array

Topics: Developer Forum, User Forum
Dec 5, 2014 at 11:01 PM
I've got some issues when setting cells with special characters (as á, é, í, etc.). If I do it directly with "setCellValue" it's ok, but when I'm trying to do it with the function "fromArray" it sets the cell as "FALSE". My array is defined this way:
foreach ($reporte->result() as $fila) {
    $datosReporte[] = array(
            'Fecha'             => $fila->NombreDia." ".$fila->Fecha, 
            'Horario'           => $fila->HoraEntrada." - ".$fila->HoraSalida,
            'Entrada'           => $fila->ChecadaEntrada,
            'Salida'            => $fila->ChecadaSalida,
            'Incidencia'        => utf8_encode($fila->Tipo)
    );  
}
So the value "Incidencia", which is the one I have problems with, is already encoded. I have also checked the file encoding in Sublime Text 2 and it shows UTF-8 as well. Any ideas what might be the problem?
Coordinator
Dec 5, 2014 at 11:16 PM
The problem is likely to arise in utf8_encode($fila->Tipo). If utf8_encode() fails, then it will return a value of false
Dec 6, 2014 at 12:45 AM
Indeed, apparently the value in my array ($reporte->result()) was wrong, so I casted the value from the stored procedure that generates it (as "CAST(Tipo AS CHAR CHARACTER SET utf8) AS Tipo") and there is no more encoded needed and that solved my problem. Thank you.
Marked as answer by CassandraLAB on 12/5/2014 at 4:46 PM