在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
$file_path = "test.txt"; if(file_exists($file_path)){ $file_arr = file($file_path); for($i=0;$i<count($file_arr);$i++){//逐行读取文件内容 //echo $file_arr[$i]."<br />"; $tmpAry[$i]=explode(' ',$file_arr[$i]); } $count=count($file_arr); $offset=rand(0,$count-1); $aa=array_slice($tmpAry, $offset,1); var_dump($aa); } exit; PHP读取txt文件到数组 加了一个逐行写入 $file_path = "1.txt"; if(file_exists($file_path)){ $file_arr = file($file_path); $handle = fopen("2.txt", "a"); for($i=0;$i<count($file_arr);$i++){//逐行读取文件内容 $aa=substr($file_arr[$i],0,11)."\r\n"; if ($handle) { fwrite($handle, $aa); } } fclose($handle); } exit;
|
2022-08-15
2022-08-17
2022-11-06
2022-08-17
2022-07-18
请发表评论