怎样查询文本文件中符合条件的记录啊?
要和别的程序做集成.接口文件是下图所示格式的文本文件.首列是时间,如:"20130726-084636"表示"2013-07-26 08:46:36".我想查询某个时间段的记录,如:"2013-07-26 10:46:36"-"2013-07-27 01:46:36" 之间的记录,该怎么实现呢?20130726-084636 2.02M 0 2.284
20130726-094636 2.02M 0 2.278
20130726-104636 2.02M 0 2.288
20130726-114636 2.02M 0 2.277
20130726-124636 2.02M 0 2.269
20130726-134636 2.02M 0 2.299
20130726-144636 2.02M 0 2.281
20130726-154636 2.02M 0 2.281
20130726-164636 2.02M 0 2.278
20130726-174636 2.02M 0 2.27
20130726-184636 2.02M 0 2.273
20130726-194635 2.02M 0 2.263
20130726-204635 2.02M 0 2.267
20130726-214636 2.02M 0 2.279
20130726-224636 2.02M 0 2.275
20130726-234636 2.02M 0 2.285
20130727-004636 2.02M 0 2.382 谢谢楼主分享http://news.china.com/news100/11038989/20130626/17913671.html
http://auto.163.com/13/0731/17/954MESAA00084IK9.html 你卡在哪里?数据量大不?
把日期格式转化成时间戳比较贝 正则表达式呗! 回复 3# liuxingyuyuni
数据量很大,应在10万条的级别. 好像这个能工作,呵呵$fp=fopen('log_file','r');
while(!feof($fp)){
$str=fgets($fp,1024);
$date_=substr($str,0,8);
$time_=(int)substr($str,9,6);
$min_date=20130726;
$min_time=104636;
$max_date=20130727;
$max_time=14636;
if($date_<$min_date||$date_>$max_date){
continue;
}
if($date_==$min_date && $time_<$min_time){
continue;
}
if($date_==$max_date && $time_>$max_time){
continue;
}
# 到达这里的是符合条件的记录
echo $str;
# 如果你的记录是按时间排序的 那么大于20130727-014636后可以结束循环
}回复 1# plumdavid
回复 6# linguijiang
我文本处理刚学,fopen等命令不熟,你的例子我得好好学习学习,你的例子收藏了.
非常感谢. 一行一行的读取
//loop file
while(...) {
//record timestamp
list($date, $time) = explode('-', "20130726-084636");
$timestamp = strtotime($date . ' ' . $time);
//timestamp of start and end time
$time_start = 123;
$time_end = 246;
if( ($time_start < $timestamp) && ($timestamp < $time_end) ) {
//do something
}
}
建议set_time_limit(0),既然是中间接口数据那10W条数据量是不是有一点不太合理?你可以给上面程序提提意见,API数据这么搞不合理的。
回复 9# liuxingyuyuni
接口文件是监控日志文件,保存2年的.有什么好办法处理呢?
页:
[1]
2