在我的Android应用程序..结果从服务器获取并显示在应用程序..其中有两种语言供用户选择..英语和印地语..英语部分工作正常并正确显示。但对于印地文,... ony'???????'显示字体的insted ...但是当我在服务器中保存印地文字体..它显示为hindi字体olnly ...我使用PHP代码连接服务器..我们需要将其更改为utf8 ..我们需要改变php文件中的任何东西..我在下面给我的PHP代码和sql代码..请检查,如果有任何错误请帮助..
PHP
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
if (isset($_GET["pinnum"]))
{
$pinnum = $_GET['pinnum'];
// get a product from products table
$result = mysql_query("SELECT *FROM pin1h WHERE pinnum = $pinnum");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["pid"] = $result["pid"];
$product["pinnum"] = $result["pinnum"];
$product["pinnacle"] = $result["pinnacle"];
$product["created_at"] = $result["created_at"];
$product["updated_at"] = $result["updated_at"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
sql代码
CREATE TABLE pin1h(
pid int(11) primary key auto_increment,
pinnum int(11),
pinnacle text,
created_at timestamp default now(),
updated_at timestamp
);
答案 0 :(得分:1)
只是一个但我认为你应该检查服务器上的编码,看看你发送的是否正常,因为我有一次相同的问题,结果发现服务器正在发送错误的字符串。
<?php
/*
* Following code will get single product details
* A product is identified by product id (pid)
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
mysql_query("SET NAMES 'utf8'");
// check for post data
if (isset($_GET["pinnum"]))
{
$pinnum = $_GET['pinnum'];
// get a product from products table
$result = mysql_query("SELECT *FROM pin1h WHERE pinnum = $pinnum");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["pid"] =$result["pid"];
$product["pinnum"] = $result["pinnum"];
$product["pinnacle"] = $result["pinnacle"];
$product["created_at"] = $result["created_at"];
$product["updated_at"] = $result["updated_at"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>