PHP: 去除 UTF-8 BOM

今天在作處理、轉換 csv 的東西, 碰到一個 UTF-8 的 csv 檔, 結果轉換出來的檔案因為 BOM 掛點。下面這一段可以用來將 BOM 去掉。

function remove_bom($str){  
    if(substr($str, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
        $str = substr($str, 3);
    }
    return $str;
}

tzangms

Read more posts by this author.

Subscribe to Oceanic / 海海人生

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!