If you can redefine the format of this file to something like this..
[Core]
System=Avro
Supplier=ABC Inc
[line1]
Quantity= 1
Device=ICD
ID=PA-658_ao8uY
For Clarity=PA-658_AO8UY
[line2]
Quantity=10
Device=PSTHG
ID=tg675_0O09i8
For Clarity: TG675_0O09I8
You can use parse_ini_file(file,true,INI_SCANNER_NORMAL)
can give you a multi-dimensional array of all the data.
This is one alternate highly subjective solution you can use. I'm just assuming the format is stable one, and will hold for long.
<?php
$newStock = new NewStockUpdate($itemListFile);
//do anything with $newStock Object
class NewStockUpdate
{
private $System;
private $Supplier;
private $allUpdates;
function __construct($listFile)
{
$fileHandle = fopen( $listFile, "r" ) or die("Couldn't open Update file $listFile");
$lineSystem = explode(":",getLineData($fileHandle));
$lineSupplier = explode(":",getLineData($fileHandle));
$i=0;
while(true)
{
$allUpdates[$i] = new ItemData($fileHandle);
$i++;
}
}
function getSystem()
{
return $this->System;
}
function getSupplier()
{
return $this->Supplier;
}
function getUpdateList()
{
return $this->allUpdates;
}
}
class ItemData
{
public $Quantity;
public $Device;
public $ID;
public $ForClarity;
public $lastObject;
function __construct($filePointer)
{
try
{
$lineQuantity = explode(":",getLineData($filePointer));
$lineDevice = explode(":",getLineData($filePointer));
$lineID = explode(":",getLineData($filePointer));
$lineForClarity = explode(":",getLineData($filePointer));
$this->Quantity = $lineQuantity[1];
$this->Device = $lineDevice[1];
$this->ID = $lineID[1];
$this->ForClarity = $lineForClarity[1];
}
catch(Exception $e)
{
//log something
}
if(feof($filePointer))
{
$this->lastObject = true;
}
else
{
$this->lastObject=false;
}
function isLastRecord()
{
return $this->lastObject;
}
}
}
function getLineData($filePointer)
{
while(!feof($filePointer))
{
$data = fgets($filePointer);
if(empty($data)|| $data=='\n')
{
$data = fgets($filePointer);
}
else
{
return $data;
}
}
}
?>
I think the rest you can manage with thie class object. Adding these entries to db and all. You can create multiple NewStock object for various Suppliers. Hopes this helps