《PHP實例:PHP批量去除BOM頭代碼分享》要點:
本文介紹了PHP實例:PHP批量去除BOM頭代碼分享,希望對您有用。如果有疑問,可以聯(lián)系我們。
<?php /** * 去除bom頭信息 */ header("Content-Type:text/html; charset=utf-8"); $auto = 1; checkdir("D:\wamp\www\sales"); function checkdir($basedir){ if ($dh = opendir($basedir)) { while (($file = readdir($dh)) !== false) { if ($file != '.' && $file != '..'){ if (!is_dir($basedir."/".$file)) { echo "文件名稱: $basedir/$file ".checkBOM("$basedir/$file")." <br>"; }else{ $dirname = $basedir."/".$file; checkdir($dirname); } } } closedir($dh); } } 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>發(fā)現(xiàn)BOM并且已自動刪除</font>"); } else { return ("<font color=red>發(fā)現(xiàn)BOM</font>"); } } else return ("沒有發(fā)現(xiàn)BOM"); } function rewrite ($filename, $data) { $filenum = fopen($filename, "w"); flock($filenum, LOCK_EX); fwrite($filenum, $data); fclose($filenum); } ?>
歡迎參與《PHP實例:PHP批量去除BOM頭代碼分享》討論,分享您的想法,維易PHP學院為您提供專業(yè)教程。
轉載請注明本頁網(wǎng)址:
http://www.snjht.com/jiaocheng/10044.html