php3-list | 199903
Date: 03/18/99
- Next message: Calum Lasham: "RE: [PHP3] displaying search results"
- Previous message: Big Mike: "Re: [PHP3] Semi-OT: The Linux plunge"
- In reply to: James Coates: "[PHP3] Simple calendar functions"
- Next in thread: Rasmus Lerdorf: "Re: [PHP3] Simple calendar functions"
- Reply: Rasmus Lerdorf: "Re: [PHP3] Simple calendar functions"
- Reply: James Coates: "Re: [PHP3] Simple calendar functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
> 1000:1045:staff meeting:::angela:!staff
> 1025:1035:cigarette break:::jamesc:jamesc
>
> ..would end up in $hour[10], which I could then pull out later and split(:).
>
> Lack of caffeine, or something similar, is stopping me from being able to
> do this though.
>
> Any thoughts, anyone?
First, let me re-re-re-iterate that you should be using a database for
this. No matter how you might try justifying your own flat files, listen
to some of the people here who have been building systems like this for
years when they tell you that you are better off using a database.
Anyway, to answer your question.
If I was reading in this datafile and wanted to split things into a
2-dimensional array such that the above 2 entries you listed ended up
being:
$hour[10][0] = "1000:1045:staff meeting:::angela:!staff";
$hour[10][1] = "1025:1035:cigarette break:::jamesc:jamesc";
I would use a loop like this:
$fp = fopen($datafile,"r");
while(!feof($fp)) {
$line = fgets($fp,256); // 256 char max line length
$hour[(int)substr[$line,0,2]][] = $line;
}
fclose($fp);
Pretty simple. There are two concepts that are important. First, to pick
out the first two characters of the line read from the file I just used
substr(). Then I took these 2 characters and converted them to an integer
using the (int) cast. The [] at the end of the expression tells php to
put the item in the next available array position. This one tends to
confuse people. A simple example:
$a[] = 1; $a[] = 2; $a[] = 3;
Would result in an array that looks like this:
$a[0]=1
$a[1]=2
$a[2]=3
-Rasmus
-- PHP 3 Mailing List http://www.php.net/ To unsubscribe send an empty message to php3-unsubscribe <email protected> To subscribe to the digest list: php3-digest-subscribe <email protected> For help: php3-help <email protected> Archive: http://www.php.net/mailsearch.php3 List administrator: zeev-list-admin <email protected>
- Next message: Calum Lasham: "RE: [PHP3] displaying search results"
- Previous message: Big Mike: "Re: [PHP3] Semi-OT: The Linux plunge"
- In reply to: James Coates: "[PHP3] Simple calendar functions"
- Next in thread: Rasmus Lerdorf: "Re: [PHP3] Simple calendar functions"
- Reply: Rasmus Lerdorf: "Re: [PHP3] Simple calendar functions"
- Reply: James Coates: "Re: [PHP3] Simple calendar functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

