1

As I site in the title I have accented characters encoding problem. I found several solutions on the web but it does not work or I do not know how to use. at the beginning: I collect all the data in php myssql base and I use the json_encode function returns the data to the application. This is where it crashes. all fields where there is a character with accents is replaced by null. data base is either a website (which I can not change it) and it is encoded in windows-1252 itself directly inserted with wampPHP why I found a solution

$liste_amis = $bdd->query('SELECT * FROM lieux');



            $nombre_amis=0;
            while($myliste=$liste_amis->fetch()){


                foreach($myliste as &$value)
                    {
                     $value = mb_convert_encoding($value, "UTF-8", "Windows-1252");
                    }

                $output[]=array_map('utf8_encode', $myliste );




                 } 
print(json_encode($output));

but it works only for data inserted with wampPHP more it appears like this "discotA¨que" and in Logcat like this "discoth\u00c3\u00a8que"

and leftovers are always given the null

in my java code I use the BufferedReader

 try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8192);
            StringBuilder sb = new StringBuilder();
            String line = null;
            int i = 0;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
                i++;

Help

Edit :

Finally it works, solution :

mysql_query ( "'utf8' SET NAMES" );
//--....... 
 while($myliste=$liste_amis->fetch()){
$output[]=array_map('utf8_encode', $myliste);
}
print(json_encode($output,JSON_UNESCAPED_UNICODE));

java :

BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);

tanks.

1 Answer 1

2

Rewrite your code to this...

foreach($myliste as &$value)
{
    $value = mb_convert_encoding($value, "UTF-8", "Windows-1252");
}
$output[]=array_map('utf8_encode', $myliste);
}
print(json_encode($output,JSON_UNESCAPED_UNICODE));
Sign up to request clarification or add additional context in comments.

2 Comments

@toufik3119, How you mean ?
tanks @Shankar it works without converting .. I do not know why and how but it works .. tanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.