使用php

时间:2015-08-06 21:39:23

标签: java php android mysql mysqli

我在服务器上有一个mysqli表,其配置如下所示。文本数据包含一些特殊字符。我使用以下php文件将此传递给我的Android应用程序。问题是所有特殊字符都在应用程序中显示为问号。我不确定是否需要指定我们在php文件中传递unicode字符,如果是,那么如何做到这一点。它不是字体问题,因为任何硬编码到应用程序中的特殊字符都会按预期显示。



<?php


// array for JSON response
$response = array();


// include db connect class
require_once __DIR__ . '/db_connectmaths.php';

// connecting to db
$con = new DB_CONNECT();
$con->connect();

// get all gamelists from gamelists table
$result = mysqli_query($con->myconn, "SELECT * FROM `abcd`" ) or die(mysql_error());


// check for empty result
if (mysqli_num_rows($result) > 0) {
    // looping through all results
    // gamelists node
    $response["gamelist"] = array();
    
    while ($row = mysqli_fetch_array($result)) {
        // temp user array
        $gamelist = array();
        $gamelist["id"] = $row["id"];
        $gamelist["zadanie"] = $row["zadanie"];
        $gamelist["odp_a"] = $row["odp_a"];
        $gamelist["odp_b"] = $row["odp_b"];
        $gamelist["odp_c"] = $row["odp_c"];
        $gamelist["odp_d"] = $row["odp_d"];
        $gamelist["comment"] = $row["comment"];
        $gamelist["correctanswer"] = $row["correctanswer"];
        



        // push single gamelist into final response array
        array_push($response["gamelist"], $gamelist);
    }
    // success
    $response["success"] = 1;

    // echoing JSON response
    echo json_encode($response);
} else {
    // no gamelists found
    $response["success"] = 0;
    $response["message"] = "No gamelists found";

    // echo no users JSON
    echo json_encode($response);
}
?>
&#13;
&#13;
&#13;

enter image description here

1 个答案:

答案 0 :(得分:0)

What's Charset yours Datas ? When my Datas have e.g. charset cp1250 i have to transfer Strings to utf8. Change PHP script

...
while ($row = mysqli_fetch_array($result)) {
    // temp user array
    $gamelist = array();
    $gamelist["id"] = $row["id"];
    //$gamelist["zadanie"] = $row["zadanie"];
    $gamelist["zadanie"] = iconv("CP1250", "UTF-8", $row["zadanie"]);
    $gamelist["odp_a"] = $row["odp_a"];
    $gamelist["odp_b"] = $row["odp_b"];
    $gamelist["odp_c"] = $row["odp_c"];
    $gamelist["odp_d"] = $row["odp_d"];
    $gamelist["comment"] = $row["comment"];
    $gamelist["correctanswer"] = $row["correctanswer"];




    // push single gamelist into final response array
    array_push($response["gamelist"], $gamelist);
}
...

The same before i save Datas from App to Mysql i have to transfer

...
$zadanie = iconv("UTF-8", "CP1250", $_POST['zadanie']);
...