我正在使用以下代码。每次从文件中准备好一行时,我都需要将其添加到关联数组中
$fp = fopen("printers.txt", "r"); // Open ptinters.txt to be read by fgets()
// While not end of the file, read a line and store it in $printer
while (!feof($fp)) {
$printer = fgets($fp, 256);
// Split the line of text into three sections and store them into
// variables named $pName $printerType and $numPages.
$tempArray = explode(":", $printer);
$pName = $tempArray[0];
$printerType = $tempArray[1];
$numPages = $tempArray[2];
//Create 2 arrays. First stores $pName and $printerType
// second stores $pName and $numPages
}; // Close while !feof $fp loop.
fclose($fp); // close $fp file pointer stream.