我一直在獲取由此函數檢索的名稱的UTF8版本,但由於某些原因,它不會以正確的字母輸出它。PHP SimpleXML - 無法正確地將SteamID64轉換爲帶有UTF8的Steam名稱
輸出示例:
ѕqÃ…ιÑÂтâ„Â「ÑÂ」
預期輸出:
ѕqυιятℓє
我在文件上跑的字符集檢查,該字符串作爲其正在從的file_get_contents和拉動函數的輸出以及源XML文件。 MySQL也沒有得到正確的版本。
此外,SimpleXML確實支持UTF-8。
須藤文件-i DEBUG.TXT
debug.txt: txt/plain; charset=utf-8
MySQL的整理
utf8_general_ci
源XML文件頭:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
這(在代碼中兩次) -
$enc = mb_detect_encoding($xml, 'UTF-8', true);
echo 'Detected encoding '.$enc;
輸出:
Detected encoding UTF-8
Detected encoding UTF-8
我不知道還有什麼地方檢查UTF-8字符集,或者說是我我需要做的第一個地方。我希望這裏有人會知道如何獲得預期的名稱版本。提前致謝。
文本文件(日誌)輸出功能:
function log_output($message){
$file = 'debug.txt';
$current = file_get_contents($file);
$current .= $message."\n";
file_put_contents($file, $current);
}
源代碼:
// Converts SteamID(64) to the users current name on Steam.
function steamid64_to_name($steamid64) {
// Get User Profile Data
$xml = file_get_contents('http://steamcommunity.com/profiles/'.$steamid64.'/?xml=1');
$enc = mb_detect_encoding($xml, 'UTF-8', true);
echo 'Detected encoding '.$enc;
$xml = simplexml_load_string($xml, null, LIBXML_NOCDATA);
if(!empty($xml)) {
if(isset($xml->steamID)) {
$username = $xml->steamID;// Example: steamcommunity.com/profiles/76561198077095013/?xml=1
} else {
$username = "Username Not Found";
}
} else {
$username = "User XML Not Found"; // Example: steamcommunity.com/profiles/0/?xml=1
}
$enc = mb_detect_encoding($xml, 'UTF-8', true);
echo 'Detected encoding '.$enc;
return $username;
}
你如何輸出這個用戶名? –
更新了OP以顯示MySQL排序規則和將其輸出到允許我閱讀的文件的功能。 – Caffeine
您是否正在使用知道它是UTF-8文件的編輯器查看日誌文件? –