ali*_*ali 5 php android special-characters
我想从PHP页面获取一些文本到Android应用程序.只要字符是ASCII(最多128个)就没有问题,但是当我想要显示特殊字符时,如'Ţ',''(所谓的Latin-1 Supplement和/或Latin Extended-A - 见到它Unicode图表)我在我的Android应用程序( )中得到了奇怪的符号.
问题是我的Android应用程序无法处理来自Latin-1 Supplement(PHP可以)的字符,而是来自Latin Extended-A字符集(PHP不能)的字符.我不知道使用两种语言的常见字符集,因为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;
}
Run Code Online (Sandbox Code Playgroud)
所以,这段代码给了我script.php页面的内容.如果收到的文本字符是0到128,则没有问题.在其他地方,我得到奇怪的角色.
现在,这是我的PHP代码:
<?php
header("Content-Type: text/plain;charset=utf-8");
echo "Â?Â??";
?>
Run Code Online (Sandbox Code Playgroud)
我也有一个C++应用程序,它确实正确读取文本.我一整天都在尝试很多方法而且我没有得到它.谁,哪里,为什么?谢谢.
小智 1
你从哪里获取数据?如果是通过 mysql 数据库,你必须像这样指定 UTF8
mysql_query("SET NAMES 'utf8'");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
943 次 |
| 最近记录: |