Home  >  Article  >  Backend Development  >  eclipse,php代码批量收编码

eclipse,php代码批量收编码

WBOY
WBOYOriginal
2016-06-13 12:36:25824browse

eclipse,php代码批量改编码
在eclipse里指改文件编码,但只能改到非php文件。

在eclipse项目下有这么一个文件夹
.settings
下面有一个
org.eclipse.core.resources.prefs 文件
里面有类似这样的编码配置
[code=INIFile]#Wed Dec 26 12:59:37 CST 2007
eclipse.preferences.version=1
encoding//test/BlackVSWhite.java=UTF-8
encoding/=GBK







<?php //
set_time_limit(0);

$form = 'F:\work\sinykk\templates';
$to = 'F:\work\sinykk\templates';

//mb_convert_encoding ( string $str , string $to_encoding [, mixed $from_encoding ] );

copyDir($form, $to);

function copyDir($dirSrc, $dirTo,$bianma='gb2312-gbk',$extlist=array('txt','js','php','inc','html','htm','css')) { 
	
	if(!file_exists($dirTo)) {      
		mkdir($dirTo);       
	}
	if($dir_handle=@opendir($dirSrc)) {        
		while($filename=readdir($dir_handle)) {   
			if($filename!="." && $filename!="..") {  
				$subSrcFile=$dirSrc."/".$filename;    
				$subToFile=$dirTo."/".$filename;    
					
				if(is_dir($subSrcFile)) {                  
					copyDir($subSrcFile, $subToFile);    
				}
				if(is_file($subSrcFile)) {   
					$ext = extname($subSrcFile);
					if(in_array($ext,$extlist)){
						$r = file_get_contents($subSrcFile);
						$r = F_iconv($r,$bianma);
						file_put_contents($subToFile,$r);
					}else{
						copy($subSrcFile, $subToFile);
					}
				}		
			}
		}
		closedir($dir_handle);      
	}
}


function F_iconv($P_strig,$P_types){
	switch(strtolower($P_types)){
		case 'gb2312-utf8' :{ $P_strig = iconv("GB2312","UTF-8",$P_strig); break; }
		case 'gb2312-gbk' :{ $P_strig = iconv("GB2312","GBK//ignore",$P_strig); break; }
		case 'gb2312-utf8-i' :{ $P_strig = iconv("GB2312","UTF-8//IGNORE",$P_strig); break; }
		case 'gb2312-utf8-t' :{ $P_strig = iconv("GB2312","UTF-8//TRANSLIT",$P_strig); break; }
		case 'utf8-gb2312' :{ $P_strig = iconv("UTF-8","GB2312",$P_strig); break; }
		case 'utf8-gb2312-i' :{ $P_strig = iconv("UTF-8","GB2312//IGNORE",$P_strig); break; }
		case 'utf8-gb2312-t' :{ $P_strig = iconv("UTF-8","GB2312//TRANSLIT",$P_strig); break; }
	}
	return $P_strig;
}


function extname($filename)     
{
	$pathinfo=pathinfo($filename);
	return strtolower($pathinfo['extension']);
}



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn