PHP 批量处理文本大小和文本内容

<?php
header("Content-Type:text/html;charset=utf-8");
/**
 * 批量处理文件内容
 * 有aaa.txt bbb.txt ccc.txt ddd.txt 四个文件
 * 我们需要删除含有 不文明 或者字节小于10的文件
 * 1.循环文件名
 * 2.filesize判断文件大小 <10删掉
 * 3.>10 判断时候有 不文明 的敏感词,如果有,使用unlink删除
 **/
foreach(array('aaa.txt', 'bbb.txt', 'ccc.txt', 'ddd.txt') as $v){
	$file = 'txt/'.$v;
	//判断大小
	if (filesize($file) < 10) {
		echo $file . "小于10个字节<br>";
		//unlink($file);
		continue;
	}
	//大于10字节,判断内容
	$cont = file_get_contents($file);
	if (stripos($cont, '不文明') !== false) {
		echo $file . "有不文明用语<br>";
		//unlink($file);
	}
}

效果图:

 

猜你喜欢

转载自onestopweb.iteye.com/blog/2340894