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
相关文档:
http://blog.developers.api.sina.com.cn/?p=264
最近MemcacheDB邮件列表和研发部那边同事报告PHP的memcache客户端php-memcache经常出 现断连接的问题:
PHP Notice: Memcache::get(): Server ………. (tcp 11211) failed with: Failed reading line from stream (0) with pecl-memcache 3.*
&h ......
函数原型:mixed str_replace(mixed needle,mixed new_needle,mixed haystack[,int &count]);
needle:要被替换的字符串,new_needle:替换用的字符串,haystack:操作字符串,count:替换次数【可选参数】
我们重点试验前三个在使用数组是的执行方式:
&n ......
//最好先建立一个 upload/public这个文件夹,以下是upload.php
<?php
/**
*********************************************
参数设定
*********************************************
**/
//最大上传文件大小
$MAX_SIZE = 20000000;
//设置Mine类型
$FILE_MIMES = array
('image/jpeg','image/jpg','image/gif ......
原文链接:http://www.phpdo.net/index.php/20100411/56.html
在PHP中使用foreach函数可以遍历数组。Foreach仅能用于数组,语法如下:
Foreach(array as $value) statements
Foreach(array as $key=>$value) statement
第一种语法遍历数组时,每次循环时,当前单元的值被赋给$value,数组内部的指针向前 ......
从HTML文件中读取指定字符串
原贴地址:http://topic.csdn.net/u/20100322/10/d7401c38-10b7-4231-a323-454caf946fa6.html
2.
<a title="1" href="sdfds" m ......