我有一个“产品”的 mysql 数据库,我正在通过这个 .php 代码将它们推送到应用程序。我的问题是,因为我有特殊字符,例如“ä,ö,ü”,尤其是“€”,所以这段代码对我不起作用。特殊字符只是从字符串中删除。
我在 php 中尝试了几种编码,并尝试将数据上传到 windows 1252 以及 latin 1、2、15 中的数据库。
结果可以在这里看到:arsdecora.net/get_all.php
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("SELECT *FROM table") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["pid"] = $row["pid"];
$product["name"] = $row["name"];
$product["kategorie"] = $row["kategorie"];
$product["beschreibung"] = $row["beschreibung"];
$product["bild"] = $row["bild"];
$product["preis"] = $row["preis"];
$products[] = array_map(function ($string) { return mb_convert_encoding($string, 'Windows-1252', 'UTF-8'); }, $product);
}
$data = array(
//'success' => 1,
'products' => $products
);
}
echo json_encode($data); // make it slightly more readable
?>