Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24
如何將 utf8 + bom 轉為 utf8 的編碼格式 – unethost無限空間虛擬主機 技術分享部落格

如何將 utf8 + bom 轉為 utf8 的編碼格式

關於檔案編碼的問題,我們之前在”網頁文件的編碼狀況
提過如果是特殊編碼,檔案開啟時不能隨意破壞其編碼,
否則會導致亂碼。

今天遇到一個很特殊的狀況,原以為是單純的utf8問題,
其php程式的編碼使用了utf8 + bom,
上傳至主機後,瀏覽器的讀取都會出現亂碼,
無論是修正php.ini或是mysql都是異常。
這時需要手動去調整,強制使用utf8而不是使用utf8+bom,
所以來介紹幾種調整的方式:

1.透過線上調整:
獨立主機用戶,可以考慮在ssh底下使用 iconv,其語法是:
iconv -f original_charset -t utf-8 oldfile > newfile

2.使用文字編輯器:
  重新編輯及儲存其格式,像是windows7以上的記事本程式,
另存新檔選擇utf8格式即可。

有趣的部份是,經我們查詢像pspad這類免費編輯器
內建的輸出已經沒有支援utf8+bom格式,看來以前舊版的編輯器,
生出相當的災情。

3.修改程式的程式碼:
在head前面加上下列語法,可以強制瀏覽器進行判斷:

header('content-type: text/html; charset: utf-8');
ob_start('ob');
function ob($buffer)
{
return str_replace("\xef\xbb\xbf", '', $buffer)
}

utf8+bom據說是以前win2000時代,
為了區別ASCII和utf8所生出來的產物,
經過這幾年的使用習性,現在新的套裝程式,
就單純是utf8格式,不太會撞到這個問題,
我們自己好幾年都沒遇過,
突然有站長反應,也嚇了我們一跳。

 

(本篇教學由unethost.com客服撰寫)

延伸閱讀:如何備份Cpanel後台安裝的套裝程式?

安裝上述的軟體,我們提供虛擬主機試用,七天滿意保證,
功能完整使用不受限制,歡迎點我申請。