通过截击和php在android中发布utf8(波斯语或阿拉伯语)
我想通过php和截击向服务器发送波斯文本 问号被发送,或者在Android上编码时,在mysql表中是这样的: %D8%AA%D9%86%D9%86%D8%AA 我在Android上使用了URLEncoder.encode 在php中 @mysqli_查询($connect,“SET CHARACTER SET utf8;”) 在mysql中,所有列都在两种模式下进行测试:utf8通用ci和波斯ci 对不起,我的母语不是英语通过截击和php在android中发布utf8(波斯语或阿拉伯语),php,android,mysql,utf-8,android-volley,Php,Android,Mysql,Utf 8,Android Volley,我想通过php和截击向服务器发送波斯文本 问号被发送,或者在Android上编码时,在mysql表中是这样的: %D8%AA%D9%86%D9%86%D8%AA 我在Android上使用了URLEncoder.encode 在php中 @mysqli_查询($connect,“SET CHARACTER SET utf8;”) 在mysql中,所有列都在两种模式下进行测试:utf8通用ci和波斯ci 对不起,我的母语不是英语 String url = mylib.clsVars.get_u
String url = mylib.clsVars.get_url(2);
progressDialog.show();
progressDialog.setCancelable(false);
final StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
progressDialog.hide();
Log.i("response: ",response.toString() );
if (response.startsWith("")) {
response = response.replaceFirst(" ", "");
}
if (Objects.equals(response, "done"))
{
Toast.makeText(con, "با موفقیت ارسال شد", Toast.LENGTH_LONG).show();
edt_title.setText("");
edt_desc.setText("");
edt_group.setText("");
gid="";
bitmap1=null;
bitmap2=null;
bitmap3=null;
img1.setImageResource(R.drawable.no_image);
img2.setImageResource(R.drawable.no_image);
img3.setImageResource(R.drawable.no_image);
}else
{
Toast.makeText(con, response+"خطا در ارسال", Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.hide();
Log.i("VolleyError in insert: ",error.toString() );
Toast.makeText(con, "خطا در ارسال", Toast.LENGTH_LONG).show();
}
}
)
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> map =new Hashtable<String,String>();
String img1="",img2="",img3="";
String title1=null,desc1=null,vid1=null,gid1=null;
try {
title1= URLEncoder.encode(edt_title.getText().toString(), "UTF-8");
desc1= URLEncoder.encode(edt_desc.getText().toString(), "UTF-8");
vid1= URLEncoder.encode(edt_video.getText().toString(), "UTF-8");
gid1= URLEncoder.encode(gid, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
map.put("t_title", title1);
map.put("t_desc", desc1);
map.put("t_vid", vid1);
map.put("gid", gid);
map.put("t_map_lat", String.valueOf(map_lat));
map.put("t_map_lon", String.valueOf(map_lon));
if (bitmap1 != null)
img1=image_base64(bitmap1);
if (bitmap2 != null)
img2=image_base64(bitmap2);
if (bitmap3 != null)
img3=image_base64(bitmap3);
map.put("img1",img1);
map.put("img2",img2);
map.put("img3",img3);
return map;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(con);
requestQueue.add(stringRequest);
stringurl=mylib.clsVars.get\uurl(2);
progressDialog.show();
progressDialog.setCancelable(假);
final StringRequest StringRequest=新StringRequest(Request.Method.POST,url,
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
progressDialog.hide();
Log.i(“response:,response.toString());
如果(响应。开始使用(“ï”?){
response=response.replaceFirst(“ï»?,”);
}
if(Objects.equals(响应,“完成”))
{
Toast.makeText(con,“Toast.LENGTH”.show();
edt_title.setText(“”);
edt_desc.setText(“”);
edt_group.setText(“”);
gid=“”;
bitmap1=null;
bitmap2=null;
bitmap3=null;
img1.setImageResource(R.drawable.no_图像);
img2.setImageResource(R.drawable.no_图像);
img3.setImageResource(R.drawable.no_图像);
}否则
{
Toast.makeText(con,response+“Toast.LENGTH”show();
}
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
progressDialog.hide();
Log.i(“插入中的截击错误:”,error.toString());
Toast.makeText(con,“Toast.LENGTH”.show();
}
}
)
{
@凌驾
受保护的映射getParams()引发AuthFailureError{
Map Map=newhashtable();
字符串img1=“”,img2=“”,img3=“”;
字符串title1=null,desc1=null,vid1=null,gid1=null;
试一试{
title1=URLEncoder.encode(edt_title.getText().toString(),“UTF-8”);
desc1=URLEncoder.encode(edt_desc.getText().toString(),“UTF-8”);
vid1=URLEncoder.encode(edt_video.getText().toString(),“UTF-8”);
gid1=URLEncoder.encode(gid,“UTF-8”);
}捕获(不支持的编码异常e){
e、 printStackTrace();
}
地图放置(“图名”,标题1);
地图放置(“描述”,描述1);
地图放置(“t_vid”,vid1);
地图放置(“gid”,gid);
put(“t_map_lat”,String.valueOf(map_lat));
put(“t_map_lon”,String.valueOf(map_lon));
如果(位图1!=null)
img1=图像_base64(位图1);
如果(位图2!=null)
img2=图像_base64(位图2);
如果(位图3!=null)
img3=图像_base64(位图3);
地图放置(“img1”,img1);
地图放置(“img2”,img2);
地图放置(“img3”,img3);
返回图;
}
};
RequestQueue RequestQueue=Volley.newRequestQueue(con);
添加(stringRequest);
和php代码:
<?php
require_once("****");
$error = array();
if( isset( $_POST['t_title'] ) && ( !empty( $_POST['t_title'] ) ) &&
isset( $_POST['t_desc'] ) && ( !empty( $_POST['t_desc'] ) ) &&
isset( $_POST['t_map_lat'] ) && ( !empty( $_POST['t_map_lat'] ) ) &&
isset( $_POST['t_map_lon'] ) && ( !empty( $_POST['t_map_lon'] ) ) &&
isset( $_POST['img1'] ) && ( !empty( $_POST['img1'] ) )
&&
isset( $_POST['img2'] ) && ( !empty( $_POST['img2'] ) )
&&
isset( $_POST['img3'] ) && ( !empty( $_POST['img3'] ) )
&&
isset( $_POST['gid'] ) && ( !empty( $_POST['gid'] ) )
&&
isset( $_POST['t_vid'] ) && ( !empty( $_POST['t_vid'] ) ) )
{
$t_title1 =$_POST['t_title'] ;
$t_desc = utf8_decode($_POST['t_desc']) ;
$t_map_lat = $_POST['t_map_lat'] ;
$t_map_lon = $_POST['t_map_lon'] ;
$cat = utf8_decode( $_POST['gid']) ;
$t_vid = utf8_decode( $_POST['t_vid']) ;
$t_title = mb_convert_encoding($t_title1,'HTML-ENTITIES','utf-8');
$rand = rand( rand(5 , 50) , rand( 500 , 900 ) );
$location1 = "pics/" .$rand.
"_" . date("i") . "_" . date("d-m-Y") ."1". ".jpg";
$location2 = "pics/" .$rand.
"_" . date("i") . "_" . date("d-m-Y")."2" . ".jpg";
$location3 = "pics/" .$rand.
"_" . date("i") . "_" . date("d-m-Y") ."3". ".jpg";
$img1 =base64_decode( $_POST['img1']);
$img2 =base64_decode( $_POST['img1']);
$img3 =base64_decode( $_POST['img3']);
$resultOfCreatingImage1 = file_put_contents( $location1 , $img1 );
$resultOfCreatingImage2 = file_put_contents( $location2 , $img2 );
$resultOfCreatingImage3 = file_put_contents( $location3 , $img3 );
$img = "http://tourist.tech9web.com/".$location1.";".
"http://tourist.tech9web.com/".$location2.";"."http://tourist.tech9web.com/".$location3;
if( $resultOfCreatingImage1 == false )
{
$error['error'] = "failure_creating_image";
}
$query= "INSERT INTO places(t_title,t_desc,t_map_lat,t_map_lon,gid,t_img,t_vid) " .
"VALUES('".$t_title."', '".$t_desc."', '".$t_map_lat."', '".$t_map_lon."', '".$cat."','".$img."','".$t_vid."')";
$connect = @mysqli_connect( $hostname , $username , $password , $database );
if( $connect )
{
@mysqli_query( $connect , "SET CHARACTER SET utf8;" );
@mysqli_query( $connect , $query );
if( @mysqli_affected_rows( $connect ) > 0 )
{
$error['error'] = "done";
}
else
{
@unlink( $location );
$error['error'] = "failure_inserting_database!";
}
}
else
{
@unlink( $location );
$error['error'] = "failure_connecting_database";
}
}
else
{
$error['error'] = "failure_post";
}
die ( json_encode( $error['error'] ) );
?>
尝试将表排序规则更改为utf8\u unicode\u ci
排序规则与编码无关
我猜你是在期待“代码”?在字符集utf8
(或utf8mb4
)中编码时,即十六进制D8AAD986D986D8AA
(无百分号)
每个%
之后是否真的有空格
%xx
来自哪里?那真的在桌子上吗?或者有什么东西在为你显示十六进制
为什么在response=response.replaceFirst(“ï»?,”)中的BOM表后面包含空格代码>
使用任何类型的编码器/解码器通常都会适得其反
请提供SELECT HEX(col)…
以便我们可以查看表中是否只有类似D8AAD986D986D8AA的内容。每个阿拉伯字母编码为2字节码:Dxyy
您需要提供更多信息。。。如何将数据发送到mysql。。。你有php脚本吗?html表单?你能告诉我们吗?在cpanelin mysql中使用php插入了%D8%AA%D9%86%D9%86%D8%AA