【问题标题】:How to use UTF-8 for non-English characters in POST method in PHP如何在 PHP 的 POST 方法中对非英文字符使用 UTF-8
【发布时间】:2017-08-05 17:52:33
【问题描述】:

我需要将文本从 Android 发送到服务器上的数据库,但我遇到了一些非英文字符的问号。

PHP 代码:

<?php

header('Content-Type: text/html; charset=utf-8'); 
$con=mysql_connect("xxxxx","xxxxx","123456");
mysql_select_db("xxxxx",$con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
$user=$_POST['username','utf8'];
$matn=$_POST['matn','utf8'];
$status=$_POST['status','utf8'];
if($user!=""){
    $sqlQ="insert into content(username,matn,status) VALUES('$user','$matn','$status')";
    $result=mysql_Query($sqlQ);
    if($result){
        print "ok";
    }
    else
    {
        print "no";
    }
}else{
    print "-";
}
mysql_close($con);

?>

【问题讨论】:

  • POST 数组在索引中没有编码作为第二个参数
  • UTF-8 all the way through的可能重复
  • 是的,那些 utf8 是多余的,我删除了那些但不起作用
  • 也在连接上设置字符集 (mysql_set_charset())。数据库中任何已经是错误字符集的数据都不会被修复
  • 我设置了这个但不起作用,我不知道该怎么办

标签: php mysql post utf-8


【解决方案1】:

不要使用已弃用的mysql_* 接口,使用mysqli_* 或PDO。

数组$_POST 中的第二维是什么?

问号表示数据存储不正确;见http://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored

【讨论】:

    猜你喜欢
    • 2018-06-12
    • 2016-09-08
    • 1970-01-01
    • 2010-10-17
    • 2018-09-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多