檢查php文件中是否含有bom的函數(shù)
更新時間:2012年05月31日 23:11:30 作者:
檢查php文件中是否含有bom的函數(shù)代碼,需要的朋友可以參考下
復(fù)制代碼 代碼如下:
<?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>");
}
} www.dbjr.com.cn
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操作MySQL中BLOB字段的方法示例【存儲文本與圖片】
這篇文章主要介紹了PHP操作MySQL中BLOB字段的方法,結(jié)合具體實例形式分析了php使用mysql的BLOB字段存儲新聞內(nèi)容與圖片的相關(guān)操作技巧,需要的朋友可以參考下2017-09-09PHP實現(xiàn)的AES雙向加密解密功能示例【128位】
這篇文章主要介紹了PHP實現(xiàn)的AES雙向加密解密功能,結(jié)合實例形式分析了基于AES算法的加密解密類定義與使用技巧,需要的朋友可以參考下2018-09-09php數(shù)組函數(shù)序列 之shuffle()和array_rand() 隨機函數(shù)使用介紹
shuffle與array_rand定義和用法,需要的朋友可以參考下。2011-10-10