Chinaunix首页 | 论坛 | 博客
  • 博客访问: 61182
  • 博文数量: 15
  • 博客积分: 102
  • 博客等级: 民兵
  • 技术积分: 100
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-31 12:03
文章分类

全部博文(15)

文章存档

2014年(4)

2012年(11)

分类: PHP

2014-04-26 11:11:15

/**
 * Created by JetBrains PhpStorm.
 * User: lenovo
 * Date: 14-4-26
 * Time: 上午10:45
 * To change this template use File | Settings | File Templates.
 */
//EF BB BF这三个字节称为bom头
function hasbom(&$content) {
    $firstline = $content[0];
    return ord(substr($firstline, 0, 1)) === 0xEF
    and ord(substr($firstline, 1, 1)) === 0xBB
    and ord(substr($firstline, 2, 1)) === 0xBF;
}
function unsetbom(&$content) {
    hasbom($content) and ($content[0] = substr($content[0], 3));
}
function write($filename, &$content) {
    $file = fopen($filename, 'w');
    fwrite($file, implode($content, ''));
    fclose($file);
}
function filenames($path) {
    $directory = opendir($path);
    while (false != ($filename = readdir($directory))) strpos($filename, '.') !== 0 and $filenames[] = $filename;
    closedir($directory);
    return $filenames;
}
function process($path) {
    $parent = opendir($path);
    while (false != ($filename = readdir($parent))) {
        echo $filename."/n";
        if(strpos($filename, '.') === 0) continue;
        if(is_dir($path.'/'.$filename)) {
            process($path.'/'.$filename);
        } else {
            $content = file($path.'/'.$filename);
            unsetbom($content);
            write($path.'/'.$filename, $content);
        }
    }
    closedir($parent);
}
process('./protected');//文件路径
阅读(2802) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~