本程式碼使用到了iconv的函數,請先在phpinfo裡查詢你的PHP是否支援運行這個函數。
新增一個PHP檔(如changecharset.php),內容如下:
<?
$t = $_GET['target'];
$i = $_GET['input'];
$o = $_GET['output'];
if (!$f=file_get_contents($t) and !$mime=mime_content_type($t)) {
die("Failed");
}
$f = iconv($i,$o,$f);
header('Content-Type: $mime; charset=$o');
echo $f;
exit;
?>
接著執行這個程式,例如如果你想要轉換 http://tw.yahoo.com/ 這一網頁為UTF-8編碼,由於這一來源頁的編碼是Big5,所以執行http://...changecharset.php?target=http://tw.yahoo.com/&input=big5&output=utf-8
就可以得到像這樣的結果。注意編碼代碼請輸入正確。有問題歡迎提出。