> -----Original Message-----
> From: Walter Torres [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, October 22, 2003 3:27 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] there has to be a better way...
> 
> 
> "Daevid Vincent" <[EMAIL PROTECTED]> wrote in message
> news:[EMAIL PROTECTED]
> > Here is a snippet from my dhcp web page found on my site 
> below... Not
> > exactly what you want, but could help you start...
> 
> thanks!
> 
> 
> > // read in the dhcp_map.ini file to map MAC addresses to images
> > $mapFile = "./dhcp_map.ini";
> > if( $fp = @fopen($mapFile, "r") )
> > {
> > while( $line = fgets($fp, 1024) )
> 
> this pulls out 1024 bytes of data form the file. right?
> or does this pull UPTO 1024 bytes of data or the EOL, which 
> ever is first?
> if fgets() onlt pulls out so much data, not to EOL, why use it?

Yes. Keeps getting 1024 byte chunks until EOL as per the documentation.

> 
> > if ($line{0} != "#") $tempMap .= $line;  // strip
> > out # comments
> > } else echo "ERROR: Can't read ".$mapFile."<BR>";
> > fclose ($fp);
> > $map = explode("\n", $tempMap);
> 
> Now make an array of these line. Right?

Ignore comment lines (#) 
Yes, explode the entire file in to one line per array key.

> > for($i = 0; $i < count($map); $i++)
> > {
> > list($mac, $image, $name) = preg_split("/\s/",$map[$i], -1,
> > PREG_SPLIT_NO_EMPTY);
> 
> walk down the map array.
> split each element on the SPACE, but don't deal with blank lines

Take each line/key of the array and split it into another array of 'stuff'
Ignore any spaces between chunks of data. If you look at the data file,
you'll understand.

> seems almost the same.
> nice use of PREG_SPLIT. I guess that helps with the BLANK lines.

It helps with blank space between MAC, image and name columns on a single
line.

> If I understand right, if I pull out 1028 of data, the '#' on 
> each line
> could be anywhere in that buffer, not just at the first character.

Yeah, in my case, I only count a # at the beginning of a line AKA $line{0}

> That's why I pulled in the entire file into a string var and 
> then exploded it into an array split on EOL characters.
> 
> Am I missing something?
> 
> Thanks for your sample.

Np.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to