PHP use utf8_decode with msqli_fetch_assoc

0

Good morning everyone, Use as hosting, HOSTINGER and after trying to contact the technical service and not solve the problem I come to the experts of this forum.

I am doing a webservice in php, I have already managed to store characters in the database with accents or ñ, but when sending them back there is no way, I get strange symbols ...

I'm doing this:

        $consulta="SELECT emei, obsServicio FROM 'voluntarioServicio' WHERE 'id'= ".$id;
        $resultado= mysqli_query($link,$consulta);
        $arraySalida = array();
                while($registro = mysqli_fetch_assoc ($resultado) ):

                         $cadena = "{$registro['emei']};{$registro['obsServicio']}";
                         $arraySalida[]= $cadena;
                endwhile;
        echo utf8_decode( implode(":",$arraySalida));  

But it should not work entirely correct since it does not decode the accent that does appear in phpMyAdmin, I think the solution is to put the utf_decode () in $ regristo [''], but I do not know how ...

I have also tried:

echo implode(":",utf8_decode($arraySalida));  

but still showing odd characters

Any ideas?

PS: I've also tested htmlspecialchars () and htmlentities () for trying more decode functions

    
asked by midlab 07.02.2017 в 11:56
source

2 answers

0

Try using the utf8_decode in the registry value before forming your string:

$emei = utf8_decode($registro['emei']);
$obsServicio = utf8_decode($registro['obsServicio']);
$arraySalida[] = "{$emei};{$obsServicio}";

You no longer use the $ string variable and do not forget to remove the utf8_decode in your echo line.

    
answered by 07.02.2017 в 13:40
0

You can use mysqli_set_charset when creating your connection, since this function specifies a default character for your data delivery.

Try to put this after making your connection

mysqli_set_charset($con,"utf8");//recibe tu conexion creada y el caracter a especificar
    
answered by 07.02.2017 в 14:20