Justtechjobs.com Find a programming school near you






Online Campus Both


php3-list | 199903

Re: [PHP3] Simple calendar functions From: James Coates (jamesc <email protected>)
Date: 03/18/99

At 10:03 18/03/99 -0500, Rasmus Lerdorf wrote:

>> ..would end up in $hour[10], which I could then pull out later and
split(:).
>>
>> 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.

Yes, yes, yes. I know. But my justification is that I'm struggling with
this at the moment and as a learning experience being told 'you're doing it
all wrong' is not particularly useful. ;) When I'm confident with my PHP
*then* I might start thinking about other more exciting things.

No point trying to run before I can walk, right?

>Anyway, to answer your question.
>
> $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);

Ah right. I hadn't thought of while(!feof()); another to add to my list of
things to remember next time I do it. :)

Ok. What was confusing me was that I was going to do;

$calendar[$hour]=array($first_entry,$second_entry...)

but I couldn't work out what the maximum value of $xx_entry would be and
thus couldn't do it.

Using $array[1][2] is a giddy height I have yet to soar to. I was, however,
familiar with the $spludge[]; concept.

My solution was particularly shonky, I'm afraid.

  $read=fopen($file,"r");
  $count=0;

  while($read)
  {
  $x=fgets($read,512);
   if (!$x) { break; }
  $ctime=substr($x,0,2);
   for ($h=0; $h<=23; $h++)
   {
    if ($ctime==$h) { $calendar[$h].="$x\n"; }
   }
  $count++;
  }
 fclose($read);

Then later I split the file on "\n" and then again later (when I need the
information) on ":;".

Sorry. I'm not being obstenate by refusing to use databases; I just don't
want to get too far from the shallow end. Yet.

Thanks for your help.

James.

-- 
------------------------------------------------------------------------------
James Coates			 		            http://www.c2.net/
Web Developer						    t: +44 1635 523700
c2net Europe Limited					    f: +44 1635 552529

-- 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>