php批量清除空行(著作权登记源码需要)

strip_whitespace() 

php读取txt文件并分割行替换空字符串

$handler = opendir('zhuzhuoquan');//文件夹名
$ii=0;
$str = '';
while( ($filename = readdir($handler)) !== false ) 
{	
	if($filename =='.' || $filename=='..' || $filename=='views') continue;
	$ii++;
	//echo $ii.'. '.$filename.'<br>';

	$file_path = 'zhuzhuoquan/'.$filename;
	$str .=trim_file($file_path);
}
echo $str;


function trim_file($file_path)
{
	$file = fopen($file_path, "r");
	$user=array();
	$i=0;
	$str = '';
	//输出文本中所有的行,直到文件结束为止。
	while(! feof($file))
	{
		$row = fgets($file);
		$row = trim($row);
		if(!$row) continue;
		$row_first = substr($row, 0, 2);//  /* // * 
		$row_first1 = substr($row, 0, 7);//  defined
		if(in_array($row_first, array("/*", "//", "* ", "*/","<?"))) continue;
		if(in_array($row_first1, array("defined"))) continue;


		$row_first2 = substr($row, 0, 5);//  defined
		if(in_array($row_first2, array("class")))
		{
			$row = "/* End of class */ \r\n".$row;
		}

 
		$user[$i]= $row;//fgets()函数从文件指针中读取一行
		$str	.= $row."\r\n";
		$i++;
	}
	fclose($file);
	$user=array_filter($user);
	//print_r($user);
	return $str;
}
exit;
$a			= "ss.txt";

$file = fopen($a, "r");
$ary=array();
$i=0;
$str = '';
//输出文本中所有的行,直到文件结束为止。
while(! feof($file))
{
	$row = fgets($file);
	$row = trim($row);
	if(!$row) continue;
	$ary[$i]= $row;//fgets()函数从文件指针中读取一行
	$str	.= $row."\r\n";
	$i++;
}
fclose($file);
$ary=array_filter($ary);
echo $str;exit;
exit;

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值