【问题标题】:POST Cyrillic letters PHP results in special charactersPOST西里尔字母PHP导致特殊字符
【发布时间】:2017-03-15 04:57:41
【问题描述】:

西里尔字母在 db 中作为规范符号发布。

这是我的 php 代码

    <?php 
    header('Content-Type: text/html; charset=utf-8');
    include("../connection.php");
    $data = json_decode(file_get_contents("php://input"));
    $address = "Коля";
    $description = $data->description;
    $alt = $data->lat;
    $lon= $data->lng;
    $q = "INSERT INTO pitches (address, description,alt,lon) VALUES (:address, :description,:alt,:lon)";
    $query = $db->prepare($q);
    $execute = $query->execute(array(
        ":address" =>  $address,
        ":description" => $description,
        ":alt"=>$alt,
        ":lon"=>$lon

    ));
    echo mb_detect_encoding($description);

    ?>

我还使用 AddDefaultCharset UTF-8 将 .htaccess 文件添加到我网站的根目录

这是我从 phpmyadmin 截取的截图:

我到处都有 utf8 编码,但我的 php 仍然向我发布像这样的 ÐšÐ¾Ð»Ñ 数据。我已经尝试了我所知道的一切,但不明白出了什么问题。

echo mb_detect_encoding($description) 显示 ANSII,
echo mb_detect_encoding($address) 显示 UTF-8 非常感谢您的帮助。

【问题讨论】:

    标签: php mysql .htaccess


    【解决方案1】:

    你试过mysql set charset吗?

    <?php
    $con=mysqli_connect("localhost","my_user","my_password","my_db");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    
    // Change character set to utf8
    mysqli_set_charset($con,"utf8");
    
    mysqli_close($con);
    ?>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-04-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-19
      • 2011-09-09
      相关资源
      最近更新 更多