php bom去除工具,php批量去除bom的代码_PHP教程

WBOY
Freigeben: 2016-07-13 10:31:28
Original
867 Leute haben es durchsucht

php批量去除文件bom代码的功能,支持文件夹批量去除。具体php文件代码如下:

<?php header('content-Type: text/html; charset=utf-8');
$auto=1;/*设置为1标示检测BOM并去除,设置为0标示只进行BOM检测,不去除*/
$basedir='.';
$loop=true;//www.phpernote.com
echo '当前查找的目录为:'.$basedir.'当前的设置是:';
echo '(1)',$loop?'检查当前目录以及当前目录的子目录':'只针对当前目录进行检测';
echo '(2)',$auto?'检测文件BOM同时去除检测到BOM文件的BOM<br />':'只检测文件BOM不执行去除BOM操作<br>';

checkdir($basedir,$loop);
function checkdir($basedir='',$loop=true){
	$basedir=empty($basedir)?'.':$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{
					if(!$loop) continue;
					$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">找到BOM并已自动去除</font>');
		}else{
			return (' <font color="red">找到BOM</font>');
		}
	}else{
		return (' 没有找到BOM');
	}
}
function rewrite($filename,$data){
	$filenum=fopen($filename,'w');
	flock($filenum,LOCK_EX);
	fwrite($filenum,$data);
	fclose($filenum);
}
Nach dem Login kopieren

将以上代码保存为后缀为php的文件放到需要去除bom的文件目录里面,然后运行该php文件,将会对该目录以及该目录所有的子目录下的文件进行bom检查并去除bom,运行结果页面如下:

php bom去除工具,php批量去除bom的代码

您可能感兴趣的文章

  • PHP实现限制域名从而保护源代码不被拷贝
  • PHP在引号前面添加反斜杠的原因及PHP去除反斜杠的办法,三种办法关闭php魔术引号
  • 用PHP函数memory_get_usage获取当前PHP内存消耗量以实现程序的性能优化
  • php如何清除html格式并去除文字中的空格然后截取文字
  • php程序员们必须知道的PHP代码优化的40条
  • 通用的PHP防注入漏洞攻击的过滤函数代码
  • php实现将文件批量压缩打包下载
  • php error_log() 将错误信息写入一个文件

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/764082.htmlTechArticlephp批量去除文件bom代码的功能,支持文件夹批量去除。具体php文件代码如下: ?phpheader('content-Type: text/html; charset=utf-8');$auto=1;/*设置为1标示...
Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!