请问php能否将htm文件进行utf-8和gb2312之间互转? 你可以下utf-8和gb2312的dedecms啊, 把模板文件换了就行,如果用批处理或php,速度也去不了那里 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 遍历模板目录文件,用找出meta部分批量替换掉,很快 function explorerdir($sDir){ static $aTempArr=array(); $dp=opendir($sDir); while ($sFileName = readdir($dp)){ if ($sFileName !='.' && $sFileName !='..'){ $sPath=$sDir."/" . $sFileName; if ( is_dir($sPath)){ explorerdir($sPath); } else { // $filetime=date("Y-m-d H:i:s",filectime("$path")); // $fp=$path.",".$filetime; $fp=$sPath; $aTempArr[]=$fp; } } } closedir($dp); return $aTempArr;}$aFiles = explorerdir("路径");foreach($aFiles as $iKey => $sFiles) { $sContent = file_get_contents($sFiles); $sContent = str_ireplace('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />', $sContent); file_put_contents($sFiles, $sContent); unset($sContent);} 谢谢iseagold,这只是该meta,直接改meta不用editplus转码的话中文还是会乱码的,因为它本质是utf文件。回coolesting ,如果是自己做的模板或者下载人家的模板,而且数量很多,这样做就有点慢了。能快就快 方法一,找出meta 换掉。方法二,遍历文件,将文件读取后,再转换格式,再生成。 我记得window下有编码转换器,可以批量换文件编码,以前用过, 记不起不什么, 英文的,是u开头, 你去google下。 那就把源文件删除,记住删除的文件名,再fwrite就改掉了 是这个吧:http://www.20ju.com/content/V52930.htm我用它将utf-8文件转为gbk文件,结果出来时乱码的 是先file_get_contents()读取源文件的代码,在fwrite到新文件那里吗?貌似这样做还是utf的吧 function explorerdir($sDir){ static $aTempArr=array(); $dp=opendir($sDir); while ($sFileName = readdir($dp)){ if ($sFileName !='.' && $sFileName !='..'){ $sPath=$sDir."/" . $sFileName; if ( is_dir($sPath)){ explorerdir($sPath); } else { // $filetime=date("Y-m-d H:i:s",filectime("$path")); // $fp=$path.",".$filetime; $fp=$sPath; $aTempArr[]=$fp; } } } closedir($dp); return $aTempArr;}$aFiles = explorerdir("D:/wamp/www/dedecms/templets/default");foreach($aFiles as $iKey => $sFiles) { $sContent = file_get_contents($sFiles); $sContent = str_ireplace('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />', $sContent); $sContent = iconv("UTF-8", "gb2312", $sContent); unlink($sFiles); file_put_contents($sFiles, $sContent); unset($sContent);}我试了下这样是可以的 iseagold你果然是世界第一猛男,能行!!! txt文件也可以这样使用转换吗 ? PHP 下载内容乱码(非下载文件名乱码) 正则表达式尖括号不能匹配 请教一个正则表达式匹配问题 如何在php中使用ffmpeg的截图和转换功能? 在软件管理板块竟然被封杀了。。散尽全部可用分 如何判断一个URL是否存在 新手求助,怎样分类显示? 我设置了cookie的值ddd,删除後,我重新设置为一个新值,可是显示还是为ddd,例如:... 微信公众平台开发文本消息嵌入超链接失败,求助 不同浏览器下,$_SERVER数组顺序为什么不一样 像新浪微博那样子,发表文章之后,页面不转跳,文章自动显示在第一行是如何做到的啊? php socket 发送数据结构
static $aTempArr=array();
$dp=opendir($sDir);
while ($sFileName = readdir($dp)){
if ($sFileName !='.' && $sFileName !='..'){
$sPath=$sDir."/" . $sFileName;
if ( is_dir($sPath)){
explorerdir($sPath);
} else {
// $filetime=date("Y-m-d H:i:s",filectime("$path"));
// $fp=$path.",".$filetime;
$fp=$sPath;
$aTempArr[]=$fp;
}
}
}
closedir($dp);
return $aTempArr;
}
$aFiles = explorerdir("路径");
foreach($aFiles as $iKey => $sFiles) {
$sContent = file_get_contents($sFiles);
$sContent = str_ireplace('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />', $sContent);
file_put_contents($sFiles, $sContent);
unset($sContent);
}
回coolesting ,如果是自己做的模板或者下载人家的模板,而且数量很多,这样做就有点慢了。能快就快
方法二,遍历文件,将文件读取后,再转换格式,再生成。
是这个吧:http://www.20ju.com/content/V52930.htm
我用它将utf-8文件转为gbk文件,结果出来时乱码的
function explorerdir($sDir){
static $aTempArr=array();
$dp=opendir($sDir);
while ($sFileName = readdir($dp)){
if ($sFileName !='.' && $sFileName !='..'){
$sPath=$sDir."/" . $sFileName;
if ( is_dir($sPath)){
explorerdir($sPath);
} else {
// $filetime=date("Y-m-d H:i:s",filectime("$path"));
// $fp=$path.",".$filetime;
$fp=$sPath;
$aTempArr[]=$fp;
}
}
}
closedir($dp);
return $aTempArr;
}
$aFiles = explorerdir("D:/wamp/www/dedecms/templets/default");
foreach($aFiles as $iKey => $sFiles) {
$sContent = file_get_contents($sFiles);
$sContent = str_ireplace('<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />', '<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />', $sContent);
$sContent = iconv("UTF-8", "gb2312", $sContent);
unlink($sFiles);
file_put_contents($sFiles, $sContent);
unset($sContent);
}
我试了下这样是可以的