檢查php文件中是否含有bom的函數(shù)
更新時間:2012年05月31日 23:11:30 作者:
檢查php文件中是否含有bom的函數(shù)代碼,需要的朋友可以參考下
復制代碼 代碼如下:
<?php
/*檢測并清除BOM*/
if(isset($_GET['dir'])){
$basedir=$_GET['dir'];
}else{
$basedir = '.';
}
$auto = 1;
checkdir($basedir);
function checkdir($basedir){
if($dh = opendir($basedir)){
while(($file = readdir($dh)) !== false){
if($file != '.' && $file != '..'){
if(!is_dir($basedir."/".$file)){
echo "filename: $basedir/$file ".checkBOM("$basedir/$file")." <br>";
}else{
$dirname = $basedir."/".$file;
checkdir($dirname);
}
}
}//end while
closedir($dh);
}//end if($dh
}//end function
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>");
}
} m.fzitv.net
else return ("BOM Not Found.");
}//end function
function rewrite($filename, $data){
$filenum = fopen($filename, "w");
flock($filenum, LOCK_EX);
fwrite($filenum, $data);
fclose($filenum);
}//end function
?>
相關(guān)文章
php中引用&的用法分析【變量引用,函數(shù)引用,對象引用】
這篇文章主要介紹了php中引用&的用法,結(jié)合實例形式較為詳細的分析了變量引用,函數(shù)引用,對象引用的概念與相關(guān)使用技巧,需要的朋友可以參考下2016-12-12
php heredoc和phpwind的模板技術(shù)使用方法小結(jié)
Heredoc技術(shù),在正規(guī)的PHP文檔中和技術(shù)書籍中一般沒有詳細講述,只是提到了這是一種Perl風格的字符串輸出技術(shù)。但是現(xiàn)在的一些論壇程序,和部分文章系統(tǒng),都巧妙的使用heredoc技術(shù),來部分的實現(xiàn)了界面與代碼的準分離,phpwind就是一個典型的例子。2008-03-03
php獲取從百度搜索進入網(wǎng)站的關(guān)鍵詞的詳細代碼
以下是關(guān)于php該如何獲取從百度搜索進入網(wǎng)站的關(guān)鍵詞的詳細代碼,希望本文對廣大php開發(fā)者有所幫助2014-01-01
PHP中功能強大卻很少使用的函數(shù)實例小結(jié)
這篇文章主要介紹了PHP中功能強大卻很少使用的函數(shù),結(jié)合實例形式總結(jié)分析了php中非常實用的幾個函數(shù),包括函數(shù)的調(diào)用、注冊、調(diào)用、判斷等操作技巧,需要的朋友可以參考下2016-11-11

