Android应用程序和PHP脚本之间的特殊字符


Special characters between Android application and PHP script

我想从PHP页面中获取一些文本到Android应用程序中。只要字符是ASCII(最多128个)就没有问题,但当我想显示特殊字符时,如"Ţ"、"(所谓的Latin-1增补和/或Latin-Extended-A-请参阅Unicode图表)我在Android应用程序中添加了奇怪的符号(�).

问题是,我的Android应用程序无法处理Latin-1 Supplement中的字符(PHP可以),但不能处理Latin-Extended-A字符集中的字符。我不知道这两种语言应该使用什么通用字符集,因为Java能够读取PHP的字符集不是,反之亦然。

获取PHP页面内容的Java函数是:

public static String GetData() {
    byte[] Bresult = null;
    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://www.mypage.com/script.php");
    try {
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
        nameValuePairs.add(new BasicNameValuePair("var", "val"));
        post.setEntity(new UrlEncodedFormEntity(nameValuePairs, "UTF-8"));
        HttpResponse response = client.execute(post);
        StatusLine statusLine = response.getStatusLine();
        if(statusLine.getStatusCode() == HttpURLConnection.HTTP_OK){
            Bresult = EntityUtils.toByteArray(response.getEntity());
            Result = new String(Bresult, "UTF-8");
        }
    } catch (UnsupportedEncodingException e) {
        Log.w("MYAPP", "Unsupported Encoding Exception (" + e.getMessage() + ")");
    } catch (Exception e) {
        Log.w("MYAPP", "Exception (" + e.getMessage() + ") ocurred");
    }
    return Result;
}

因此,这段代码为我提供了script.php页面的内容。如果接收到的文本的字符是从0到128,则没有问题。在其他地方,我会遇到一些奇怪的角色。

现在,这是我的PHP代码:

<?php
    header("Content-Type: text/plain;charset=utf-8");
    echo "ÂŞÂĂĒ";
?>

我还有一个C++应用程序,它确实能正确阅读文本。我一整天都在尝试很多方法,但我就是不明白。谁,在哪里,为什么?谢谢

您从哪里获得数据?,如果是通过mysql数据库,则必须像下面的一样指定UTF8

mysql_query("SET NAMES 'utf8'");