核心代碼
function checkBOM ($filename) { global $auto; $contents = file_get_contents($filename); $charset[1] = substr($contents, 0, 1); $charset[2] = substr($contents, 1, 1); $charset[3] = substr($contents, 2, 1); if (ord($charset[1]) == 239 && ord($charset[2]) == 187 && ord($charset[3]) == 191) { if ($auto == 1) { $rest = substr($contents, 3); rewrite ($filename, $rest); return ("<font color=red>BOM found, automatically removed.</font>"); }else { return ("<font color=red>BOM found.</font>"); } }else return ("BOM Not Found."); }
php清除莫明輸出大法,用於輸出圖片前把前面所有輸出清空
只要在header前連用兩個函數,就可以解決...
ob_get_clean(); ob_clean(); header("Content-type: image/jpeg");
附幾個好用的BOM檢測工具:
BOM檢測.zip