php 逐行读取文本文件
工作中经常需要写一些脚本对数据做处理,get这个技能,对写脚本帮助很大!
define("ROOTPATH",dirname(__FILE__)); $filepath = ROOTPATH . "/1111/order_no.txt"; $file = fopen($filepath, "r") or exit("Unable to open file!"); //定义计数器 $i = 0; while(!feof($file)) { //计数 $i ++; $order_no = trim(fgets($file)); print $order_no . "\n"; } fclose($file); print "total rows:{$i}\n";