批处理文件的内容
有a.txt b.txt c.txt d.txt 四个文件,我们需要删除含有 funk 或者字节小于10的文件
<?php
/**
批量处理文件内容
有a.txt b.txt c.txt d.txt 四个文件
我们需要删除含有 funk 或者字节小于10的文件
1.循环文件名
2.filesize判断文件大小 <10删掉
3.>10 判断时候有funk单词,如果有,使用unlink删除
**/
foreach (array('a.txt', 'b.txt', 'c.txt', 'd.txt') as $v) {
$file = './article/'.$v;
//判断大小
if (filesize($file) < 10) {
echo $file."小于10个字节";
// unlink($file);
continue;
}
//大于10字节,判断内容
$cont = file_get_contents($file);
if (stripos($cont, 'funk') !== false) {
echo $file."有不文明用语";
// unlink($file);
}
}
/**
我把删除屏蔽了
./article/b.txt小于10个字节
./article/c.txt有不文明用语
./article/d.txt小于10个字节
**/