作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
à)。 我有UTF-8的URLEncoders,数据库也有(如果我手动引入“í”,“í”是正-6ren">
我有一个 Android 应用程序,可以将数据发送到数据库,但在数据库中,某些字符存储错误(例如:í -> à)。
我有UTF-8的URLEncoders,数据库也有(如果我手动引入“í”,“í”是正确存储的,所以我认为这不是数据库错误)并且我在我的php脚本中指出要使用UTF-8 所以我不知道我还能尝试什么。
Java
public class SendPostRequest extends AsyncTask<String, Void, String> {
protected void onPreExecute(){}
protected String doInBackground(String... arg0) {
try {
URL url = new URL("https://www.web.com/script.php"); // here is your URL path
JSONObject postDataParams = new JSONObject();
postDataParams.put("user", user);
postDataParams.put("texto", edit_text_value);
postDataParams.put("l_origen", lengor_value);
postDataParams.put("l_destino", lengdest_value);
postDataParams.put("precio", precio);
postDataParams.put("num_pal", num_pal);
Log.e("params",postDataParams.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
int responseCode=conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
BufferedReader in=new BufferedReader(new
InputStreamReader(
conn.getInputStream()));
StringBuffer sb = new StringBuffer("FUAAARK");
String line="";
while((line = in.readLine()) != null) {
sb.append(line);
break;
}
in.close();
return sb.toString();
}
else {
return new String("false : "+responseCode);
}
}
catch(Exception e){
return new String("Exception: " + e.getMessage());
}
}
@Override
protected void onPostExecute(String result) {
Toast.makeText(getApplicationContext(), result,
Toast.LENGTH_LONG).show();
}
}
public String getPostDataString(JSONObject params) throws Exception {
StringBuilder result = new StringBuilder();
boolean first = true;
Iterator<String> itr = params.keys();
while(itr.hasNext()){
String key= itr.next();
Object value = params.get(key);
if (first)
first = false;
else
result.append("&");
result.append(URLEncoder.encode(key, "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(value.toString(), "UTF-8"));
}
return result.toString();
}
PHP
$precio = $_POST['precio'];
$texto = $_POST['texto'];
$user = $_POST['user'];
$l_origen = $_POST['l_origen'];
$l_destino = $_POST['l_destino'];
$num_pal = $_POST['num_pal'];
define('HOST','***');
define('USER','***');
define('PASS','***');
define('DB','***');
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
mysql_query("SET NAMES 'utf8'");
$sql = "INSERT INTO users (username, precio, text_cli, l_origen, l_destino, num_pal) VALUES('$user','$precio','$texto','$l_origen','$l_destino','$num_pal')";
非常感谢您的宝贵时间
最佳答案
PHP/MySQL/UTF-8 中需要考虑的事项
- The database tables and text columns should be set to UTF-8
- HTML page Content-Type should be set to UTF-8
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- PHP should send a header informing the browser to expect UTF-8
header('Content-Type: text/html; charset=utf-8' );
- The PHP-MySQL connection should be set to UTF-8
mysqli_query("SET CHARACTER_SET_CLIENT='utf8'",$conn);
mysqli_query("SET CHARACTER_SET_RESULTS='utf8'",$conn);
mysqli_query("SET CHARACTER_SET_CONNECTION='utf8'",$conn);
- PHP ini has default_charset setting it should be utf-8 if you do not have access to it use ini_set('default_charset', 'utf-8');
关于java - 西类牙语字符 ("` "、 "´"、 "ñ") 未显示在数据库中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39204624/
我是 Android 的新手,我想根据我的相机获取方向。如何根据我的相机获取方向信息?你能给出一个想法吗? 最佳答案 TYPE_ORIENTATION 已弃用 我们不能再使用方向传感器了,我们可以串联
我想知道矩阵除对角线之外的 4 个主要区域的条件。 例如下面的矩阵 A=[1,2,3,4,5; 6,7,8,9,10; 11,12,13,14,15; 16,17,18,19,20;
let latitude: = 36.6839559; let longitude = 3.6217802; 此API需要东西南北参数 const API = `http://api.geonames
我是一名优秀的程序员,十分优秀!