开发者

PHP .txt file search w/display of related search info

I have a text file that contains a years worth of dates with associated dates. I am working with the file from 2009 but its structure is the same in the 2011 file, and will be in the 2012 file. As you can see each date section starts with a 1 and a space followed by a date in mmddyy format:

1 070109  
 MON JUN 29........ THU JUL 09  
 TUE JUN 30........ MON JUL 13  
 WED JUL 01........ MON JUL 13  
 THU JUL 02........ TUE JUL 14  
 FRI JUL 03........ TUE JUL 14  
        CIVIL TRAFFIC  
 MON JUN 29........ WED JUL 29  
 TUE JUN 30........ THU JUL 30  
 WED JUL 01........ FRI JUL 31  
 THU JUL 02........ MON AUG 03  
 FRI JUL 03........ MON AUG 03  

1 070209  
 TUE JUN 30........ MON JUL 13  
 WED JUL 01........ MON JUL 13  
 THU JUL 02........ TUE JUL 14  
 FRI JUL 03........ TUE JUL 14  
 SAT JUL 04........ WED JUL 15  
        CIVIL TRAFFIC  
 TUE JUN 30........ THU JUL 30  
 WED JUL 01........ FRI JUL 31  
 THU JUL 02........ MON AUG 03  
 FRI JUL 03........ MON AUG 03  
 SAT JUL 04........ TUE AUG 04  

What I need to be able to do is retrieve the associated dates listed below each heading date. I want it set up so if the user just wants the dates for 070109, they could just select the button for "Todays Court Dates". If they need court dates for a different date, they would enter the date they want, the text file would be searched for "1 $date" and the associated information would be retrieved and displayed. There's my problem...

I have been able to read the file and even diplay the entire file, but I have not figured out how to locate the "1 070109" and then d开发者_高级运维isplay only the following 12 lines of information


if you are sure that there are 12 entries for each date, I think you can just use a simple loop to do 12 times of fgets and array_push. As a result you will have an array of 12 strings.


if you want to use a text file, you will have to fopen() it first, and then you can do a fseek(), to locate the file pointer where you need. i.e: if all lines are the same, then every line (like FRI JUL 03........ MON AUG 03) is 30 bytes long. you also know that the "header" for each set of lines (1 070109) is 8 bytes long.

if you want to skip the first header, you need to fseek($file, 8) + eol (1 or 2 bytes more depending if you are using CR or CRLF). so let's suppose you are using cr instead of crlf (1 byte). that would make the header 9 bytes long.

if you know you've got "records" of 1 header and 12 lines, then you can skip:

  • 9 bytes of the header + eol
  • 30 * 12 + 30 (12 lines + an eol for each line)

an so on..

you can skip as many records as you like to get to the date where you'll assume you will have the correct information for that date. just make a function to fseek the header + the lines + eol's up to the point where you want to.

so you can skip 2 records or 5 records, each record represents a date

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜