当前位置:Gxlcms > PHP教程 > PHPfgets按行读取字符串和explode分割字符串为数组_PHP教程

PHPfgets按行读取字符串和explode分割字符串为数组_PHP教程

时间:2021-07-01 10:21:17 帮助过:1人阅读

PHP fgets按行读取字符串和explode分割字符串为数组


file.txt

类型|所在目录|文件|大小|创建时间

File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Vevay|724|2014-10-13 09:36 
File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Vincennes|884|2014-10-13 09:36
File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Winamac|932|2014-10-13 09:36 
Directory|C:\Program Files\Java\jre7\lib\zi\America|Indiana|0|2014-10-13 09:36

readfile.php

";
	
		$str = explode("|",$line);
		//print_r($str);
	
		$file_type =  $str [0];
		$dir_name =  $str [1];
		$file_name =  $str [2];
		$file_size =  $str [3];
		$create_time =  $str [4];

		echo $file_type;
		echo "
"; echo $dir_name; echo "
"; echo $file_name; echo "
"; echo $file_size; echo "
"; echo $create_time; echo "
"; } fclose($f); ?>

结果显示

File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Vevay|724|2014-10-13 09:36 
File
C:\Program Files\Java\jre7\lib\zi\America\Indiana
Vevay
724
2014-10-13 09:36 
File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Vincennes|884|2014-10-13 09:36 
File
C:\Program Files\Java\jre7\lib\zi\America\Indiana
Vincennes
884
2014-10-13 09:36 
File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Winamac|932|2014-10-13 09:36 
File
C:\Program Files\Java\jre7\lib\zi\America\Indiana
Winamac
932
2014-10-13 09:36 
Directory|C:\Program Files\Java\jre7\lib\zi\America|Indiana|0|2014-10-13 09:36 
Directory
C:\Program Files\Java\jre7\lib\zi\America
Indiana
0
2014-10-13 09:36 


www.bkjia.comtruehttp://www.bkjia.com/PHPjc/953329.htmlTechArticlePHP fgets按行读取字符串和explode分割字符串为数组 file.txt 类型|所在目录|文件|大小|创建时间 File|C:\Program Files\Java\jre7\lib\zi\America\Indiana|Veva...

人气教程排行