Re: there has to be a better way...
| From: | jsWalter | Date: | Wed, 22 Oct 2003 22:20:19 +0000 |
| Subject: | Re: there has to be a better way... | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-167189@lists.php.net to get a copy of this message | ||
"Daevid Vincent" <daevid@daevid.com> wrote in message
news:200310221924.h9MJOAq5018186@daevid...
> 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 ($line{0} != "#") $tempMap .= $line; // strip
> out # comments
> } else echo "ERROR: Can't read ".$mapFile."<BR>";
> fclose ($fp);
> $map = explode("\n", $tempMap);
OK. $tempMap is a string var. Each line of the file has a /n delimiting it.
Now make an array of these line.
Right?
> 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
...
seems almost the same.
nice use of PREG_SPLIT. I guess that helps with the BLANK lines.
if fgets() onlt pulls out so much data, not to EOL, why use it?
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.
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.
Walter