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
相关文档:
分析网站结构
既然我们已经安装 CI ,我们开始了解它如何工作。
读者已经知道 CI 实现了MVC式样。 通过对目录和文件的内容进行分类, 而不是让代码大块大块地纠集在一起。
这一章,我们将会对 MVC 理论做个简短的介绍, 然后再介绍 CI 的MVC实现方式。特别地,要了解那些目录和文件如何互相交换信息?网站结构是怎样的?以 ......
最近想写个软件玩玩,抓取网页上的内容
抓取网页内容的我放在一个文件中写成类了
以下是代码
<?php
class myhttp
{
var $_host;
var $_url;
var $_port;
var $_errno;
var $_errstr;
va ......
setcookie("cookiename","cookievalue",time()+3600,"/path",".php100.com",1);
cookiename:
是cookie的名字,可以通过cookiename调用此cookie,$_COOKIE["cookiename"];
cookievalue:
是cookie的初始值;
time():
返回UNIX时间戳,即从1970年1月1日(UTC/GMT ......
函数原型:mixed str_replace(mixed needle,mixed new_needle,mixed haystack[,int &count]);
needle:要被替换的字符串,new_needle:替换用的字符串,haystack:操作字符串,count:替换次数【可选参数】
我们重点试验前三个在使用数组是的执行方式:
&n ......
<?php
$s = "new string";
//下面双引号字符串中的符号"$"未做转义,因此$s将被替换成其变量的值
$str_1 = "双引号指定的字符串,$s";
//下面双引号字符串中的符号"$"做了转义,因此$s原封不动,不会被替换为变量$s的值
$str_2 = "双引号指定的字符串,\$s";
//单引号字符串中的"$"不用做转义即可原样输出
$str_3 ......