<?php
/**
* Search all the language files, and return them
*
* @param string $language language name such as 'zh_cn'
* @param string $root_dir the root dir which we will search in it
* @param array $res_array result array
* @return array language files array
*/
function findLanguageFiles($language,$root_dir,$res_array=array()){
$filter_dir_array = array('cache','.cache','.svn');
$d = dir( $root_dir );
while( $f = $d->read() ){
if( $f == "." || $f == ".."){
continue;
}
foreach($filter_dir_array as $v){
if($f == $v && (is_dir( "$root_dir/$f" )))
continue 2;
}
if( is_dir( "$root_dir/$f" ) ){
$res_array = findLanguageFiles($language, "$root_dir/$f", $res_array);
}
else {
if(preg_match("/(.*)".$language."/.lang/.php/$/", "$root_dir/$f", $match))
{
include("$root_dir/$f");
array_push( $res_array, "$root_dir/$f" );
}
}
}
return( $res_array );
}
/**
* erase the utf8's bom
*
* @param string $filename
* @param array $bom the bom array which we will remove them from the file head
* @return boolean true or false
*/
function eraseFilesBom($filename){
$bom = array('efbbbf');//handle utf8's bom now
if(filesize($filename) == 0){
echo "<font color='red'>'$filename' is empty</font><br/>";
return false;
}
if(!@$buffer = file_get_contents($filename)){
echo "<font color='red'>Get file '$filename' contents error</font><br/>";
return false;
}
$buffer = bin2hex($buffer);
foreach($bom as $v)
{
$buffer = preg_replace('/^'.$v.'/', '', $buffer);
}
$buffer = pack("H*",$buffer);
if(!@$res = file_put_contents($filename,$buffer)){
echo "<font color='red'>Save file '$filename' contents error</font><br/>";
return false;
}else{
echo "Clear file '$filename' succeed<br/>";
return $res;
}
}
$language = 'zh_cn'; //which language, set it as you want, such as 'zh_cn'
$language = 'nl_NL';
$root_dir = 'D:/language_tools/Dutch_Language_Pack_by_Madcap_500e_madcap3'; //which directory you will search the language files in it such as 'd:/src'
if($language!='' && is_dir($root_dir)){
$new_files = findLanguageFiles($language,$root_dir);//get all the language files array
//erase file's form
foreach($new_files as $v){
$res = eraseFilesBom($v);
}
}
?>
<?php
$文件名="PHP除bom小工具"; //网站名一般不用更改
$作者="Fengyin"; // 请保留作者的名字,对版权的尊重
$网站="http://fengyin.name"; //请保留作者的联系地址
error_reporting(7);
ob_start();
$mtime = explode(' ', microtime());
$starttime = $mtime[1] + $mtime[0];
$admin['check'] = "1"; // 1为开启密码验证 0为关闭
$admin['pass'] = "fengyin.name"; // 密码,默认密码是 fengyin.name
$onoff = (function_exists('ini_get')) ? ini_get('register_globals') : get_cfg_var('register_globals');
if ($onoff != 1) {
@extract($_POST, EXTR_SKIP);
@extract($_GET, EXTR_SKIP);
}
$self = $_SERVER['PHP_SELF'];
$dis_func = get_cfg_var("disable_functions");
if($admin['check'] == "1") {
if ($_GET['action'] == "logout") {
setcookie ("adminpass", "");
echo "<meta http-equiv=/"refresh/" content=/"3;URL=".$self."/">";
echo "<span style=/"font-size: 12px; font-family: Verdana/">退出成功......<p><a href=/"".$self."/">三秒后自动退出或单击这里退出程序界面 >>></a></span>";
exit;
}
if ($_POST['do'] == 'login') {
$thepass=trim($_POST['adminpass']);
if ($admin['pass'] == $thepass) {
setcookie ("adminpass",$thepass,time()+(1*24*3600));
echo "<meta http-equiv=/"refresh/" content=/"3;URL=".$self."/">";
echo "<span style=/"font-size: 12px; font-family: Verdana/">验证成功......<p><a href=/"".$self."/">三秒后自动跳转或单击这里进入程序界面 >>></a></span>";
exit;
}
}
if (isset($_COOKIE['adminpass'])) {
if ($_COOKIE['adminpass'] != $admin['pass']) {
loginpage();
}
} else {
loginpage();
}
}
?>
<html>
<head>
<title><?php echo $文件名;?></title>
<style type="text/css">
.header{
width:100%;
}
.menu{
float:right
}
body,td,th {
font-size: 14px;
font-family: "宋体";
a{TEXT-DECORATION:none}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
A:hover {color:red} a{color:#4169E1;}
{MARGIN-TOP:50px}();background-repeat:no-repeat;margin-right:0px;}.main_top_r{background-image:url();float:right;height:30px;width:30px;margin-left:-3px;}.over{color:yellow;background:navy}.down{color:yellow;background:navy;font-style:italic}BODY{table{font:12px Tahoma,Verdana;color:#333333;empty-cells:show;border-collapse:separate!important;border-collapse:collapse;}cursor:url('');fixed}.biaoti{font-family:"宋体";font-size:16px;color:#0000CC;}input,select,textarea{font:12px Tahoma,Verdana;color:#333333;font-weight:normal;background-color:#D4EEFD;border:1px solid #7AC4EA;}a{TEXT-DECORATION:none}
</style>
</head>
<body>
<div class="main">
<div class="header"><div class="title"><?php echo $文件名;?></div><div class="menu">
<?php
if($admin['check'] == "1"){?>
<a href="?action=logout">注销</a><?php }
?>
</div>
</div>
<h3><?echo $_POST["dir"];?>目录下的检测结果</h3>
<?
//此文件用于快速测试UTF8编码的文件是不是加了BOM,并可自动移除
//By bob 老大 www.bo-blog.com
$目录= str_replace(" ", "|", $_POST["dir"]);//接受提交的路径数据
$basedir="$目录"; //修改此行为需要检测的目录,点表示当前目录
$auto=1; //是否自动移除发现的BOM信息。1为是,0为否。
//除非你知道以下程序是干什么。不然请不要更改。
if ($dh = opendir($basedir)) {
while (($file = readdir($dh)) !== false) {
if ($file!='.' && $file!='..' && !is_dir($basedir."/".$file)) echo "filename: $file ".checkBOM("$basedir/$file")." <br>";
}
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>--Bom 已经清除完毕。</font>");
} else {
return ("<font color=red>--Bom found.</font>");
}
}
else return ("--没有检查到Bom.");
}
function rewrite ($filename, $data) {
$filenum=fopen($filename,"w");
flock($filenum,LOCK_EX);
fwrite($filenum,$data);
fclose($filenum);
}
?>
<form action="" method="POST">
目录: <input type="text" name="dir" />
<input type="submit" value="检测目录" >
</form>
请输入文件夹名比如 plugin/fanfou 后面不需要加/。如果要检测根目录输入“ . ” . 是小数点 提交既可
</br>
<div class="msg">
<div align="center">
<br/></br><br/>
<a href="<?php echo $网站;?>" target="_blank">Powered by <?php echo $作者;?></a></div>
<?php
// 登陆入口
function loginpage() {
?>
<style type="text/css">
input {font-family: "Verdana";font-size: "11px";BACKGROUND-COLOR: "#FFFFFF";height: "18px";border: "1px solid #666666";}
</style>
<form method="POST" action="">
<font color="red" style="font-size:12px;">密码为: fengyin.name 请立即修改 <br/>该程式属于危险工具会列出网站的目录里的文件,所以不建议也不推荐存放在可以访问的web地址上。若要存放请开启密码验证功能或者改名</font><br/>
<span style="font-size: 11px; font-family: Verdana">密码: </span><input name="adminpass" type="password" size="20">
<input type="hidden" name="do" value="login">
<input type="submit" value="验证密码">
</form>
<?php
exit;
}
function debuginfo() {
global $starttime;
$mtime = explode(' ', microtime());
$totaltime = number_format(($mtime[1] + $mtime[0] - $starttime), 6);
echo "Processed in $totaltime second(s)";
}
?>