钻石问号在团结 www.text.

本文关键字:www text 钻石 | 更新日期: 2023-09-27 17:55:34

我试图使用以下 c# 代码从我的本地主机获取一些文本:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class get_kings : MonoBehaviour {
public string url = "http://localhost/kings/get_kings.php";
public string firstname;
public Text countText;
IEnumerator Start() {

    // hämta hem data om kungarna
    WWW www = new WWW(url);
    // vänta på att datana laddas ner
    yield return www;
    // spara texten
    firstname =  www.text;
    Debug.Log (firstname);
    setCountText ();
}
void setCountText() {
    countText.text = firstname;
}

问题是它显示文本,但我所有的特殊字符(如 Å Ä Ö)都得到了可怕的黑色问号。无论我从数据库运行什么排序规则/字符集。

<?php include "db_connect.php"?>
<?php
//get all data from db
$sql = "SELECT *FROM testar";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["name"];
    }
} else {
    echo "0 results";
}
$conn->close();
?>

无论我运行 utf-8 utf-16 还是其他任何东西,我都无法在运行我的 Unity 应用程序时正确显示特殊字符。我可以在统一中做些什么来强制编码吗?

/埃米尔

钻石问号在团结 www.text.

我使用以下方法进行了解决方法:

mysqli_set_charset($conn,"utf8");

谢谢。

假设您要输出到浏览器,请设置 html 的字符集。 W3学校

     <meta charset="UTF-8"> 

最好确保所有作品都使用相同的字符集。