Here is a snippet from my dhcp web page found on my site below... Not
exactly what you want, but could help you start...

        // 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) )
                        if ($line{0} != "#") $tempMap .= $line;  // strip
out # comments
        } else echo "ERROR: Can't read ".$mapFile."<BR>";
        fclose ($fp);
        $map = explode("\n", $tempMap);
        //print_r($map);
        for($i = 0; $i < count($map); $i++)
        {
                list($mac, $image, $name) = preg_split("/\s/",$map[$i], -1,
PREG_SPLIT_NO_EMPTY);
                //if ( array_key_exists($mac, $machine))
$machine[$mac]->setImage($image);
                if ( isset($machine[$mac]) )
$machine[$mac]->setImage($image);
                if ( isset($machine[$mac]) && $name != "" &&
$machine[$mac]->getName() == "") $machine[$mac]->name = $name;
        }
        unset($tempMap);
        unset($map);


#  "dhcp_map.ini" file
#  MAC ADDRESS: GIF IMAGE:      NAME:
00:09:12:86:48:54       linux           LINUX
00:0B:AD:31:AA:A6       tivo            Thad's
00:0B:AD:08:38:C3       tivo            Daevid's



Daevid Vincent
http://daevid.com
  

> -----Original Message-----
> From: jsWalter [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, October 22, 2003 1:11 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP] there has to be a better way...
> 
> I need to read (write comes later) from a config file that we 
> used to handle
> manually.
> 
> I'm getting lazy, so I'm writing a web interface for this.
> 
> What I have does this...
>   - open a given file
>   - dump entire file into a string
>   - explode string into an array at the EOL marker
>   - walk down this new array
>   - decide if there is anything in current element
>   - decide if current line is a comment
>   - split line at '=' into 2 variables
>   - add new key and value from these variables back into array
>   - kill original array element
> 
> There must be a better way to do this.
> 
> All this seems a bit over kill to me.
> 
> Does anyone have any ideas on this?
> 
> Thanks
> 
> Walter
> 
> This is what I have...
> 
> <?php
> 
> $config = $list . '/home/walter/vmd/config';
> 
> // Open the file
> $handle = fopen ($config, "r");
> 
> // Read entire file into var
> $content = fread($handle, filesize($config));
> 
> // convert var into array and explode file via line break
> $content = split("\r\n", $content);
> 
> // close file
> fclose($handle);
> 
> // Loop through file contents array
> foreach ($content as $i => $value)
> {
>    // If we have any data in this line
>    if (! empty ($value))
>    {
>       // If this line is not a comment
>       if ( $value{0} != '#')
>       {
>          list($a, $b) = split("=", $value);
>          $content[$a] = $b;
>       }
> 
>       // kill original array element
>       unset($content[$i]);
>    }
> }
> 
> // show me what I have
> echo '<pre>';
> echo print_r($content);
> echo '</pre>';
> 
> ?>
> 
> # Sample config file data, just 2 lines from the file...
> #
> # The "Personal Name" of the list, used in outgoing headers.
> # If empty, default is the same as the list's username.
> # if explicitly `false', then it is redefined empty.
> LIST_NAME="RMT Working Group"
> 
> # The address of the list's admin or owner.
> # if explicitly `false', then it is redefined empty.
> [EMAIL PROTECTED]
> 
> ...
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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

Reply via email to