<?PHP/*detect and Clear BOM*/ if(isset($_get[' dir '])){ $basedir=$_get[' dir ']; }Else{ $basedir= '. '; } $auto= 1; Checkdir ($basedir); functionCheckdir ($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")." "; }Else{ $dirname=$basedir." /".$file; Checkdir ($dirname); } } }//End While Closedir($DH); }//End If ($dh}//End FunctionfunctionCheckbom ($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.")); }//End FunctionfunctionRewrite$filename,$data){ $filenum=fopen($filename, "W"); Flock($filenum,lock_ex); fwrite($filenum,$data); fclose($filenum); }//End Function?>
PHP Removal BOM