1
當我右鍵單擊瀏覽器中的xml頁面並保存AS時,使用Notepad ++打開它時,它顯示OK並顯示非英文字符。 但是,如果我編寫一個腳本來將頁面保存到我的服務器,我遇到了字符編碼問題。這真是一件令人頭疼的事情。任何幫助?謝謝。php下載xml頁面並將其轉換爲utf-8
function download_page($path)
{
//$path = htmlentities($path);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$path);
curl_setopt($ch, CURLOPT_FAILONERROR,1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 280);
$retValue = curl_exec($ch);
if (!$retValue){ //echo "erro curl";
}
@curl_close($ch);
return $retValue;
}
$file= download_page($url);
$file = mb_convert_encoding($file, 'HTML-ENTITIES', "UTF-8");
$file = utf8_encode ($file);
我需要非英文字符出現(ě,ú,..) – karto 2012-07-11 13:16:18
如果您有適當的utf-8文件,它們應該會出現。我認爲你不需要mb_convert_encoding行。但你如何寫出文件?你使用fwrite嗎?如果是,請檢查[this](http://hu.php.net/manual/en/function.fwrite.php#73764)。這是一個有點舊的帖子,但它可能有幫助。 – ttamas 2012-07-11 14:08:16