使用php清除bom示例
更新時間:2014年03月03日 14:54:36 投稿:zxhpj
本文主要介紹了使用PHP去除文件BOM頭的的示例,需要的朋友可以參考下
核心代碼
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



