php基础应用:php批量转换文件编码
遍历目录文件,替换编码部分,删除原文件,再重新转码原文件内容,重新生成新文件。
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);
}
原贴地址:http://topic.csdn.net/u/20100407/10/b5fe2152-d5b2-42a5-aa3f-cf6c499af2f1.html
相关文档:
函数原型:mixed str_replace(mixed needle,mixed new_needle,mixed haystack[,int &count]);
needle:要被替换的字符串,new_needle:替换用的字符串,haystack:操作字符串,count:替换次数【可选参数】
我们重点试验前三个在使用数组是的执行方式:
&n ......
php config
1.安装Apache2.2
2.安装php5.2(注意选择所有的库文件)
3.将phpMyAdmin解压,拷贝至Apache2.2\htdocs\phpmyadmin(该路径可以自由改变)下。
4.修改配置文件:
1)修改php.ini
具体操作:
extension_dir = "C:\Program Files\PHP\ext" (536)
extension=php ......
最近有一个香港的酒店提出需求,要到酒店业内的商务中心实行计费上网, 提供了如下技术方案:
1、设一台CENTOS5的机器做为路由,把需要计费的机器都设为用此服务器做网关。
2、服务器开启IPTABLE,通过IPTABLE控制能不能使用互联网。
记录下以下技术要点:
一、 php可以通过shell_exec来执行shell指令,但iptables的指令是r ......
//最好先建立一个 upload/public这个文件夹,以下是upload.php
<?php
/**
*********************************************
参数设定
*********************************************
**/
//最大上传文件大小
$MAX_SIZE = 20000000;
//设置Mine类型
$FILE_MIMES = array
('image/jpeg','image/jpg','image/gif ......