I have a fixed length file that I am reading and trying to process. The
file contains 3 types of records (a,b,c) each has it's own field
definition for the position on the line. Record type is always held in
position 2(php 0,1,2), with a length of 1.
I would like to process each line seperatley, evaluating the record
type, and then taking the appropriate action. Like so:
//open the import file
$import_file = fopen(dirname(_ _FILE__)."/../../data/imports/data.imp",
"r");
//make sure we can read it
if($import_file )
{
//loop to read each line
while (!feof($import_ file))
{
//read line and process accordingly
$line = fgets($import_f ile);
$record_type = substr($line, 2,1);
if($record_type =="a")
{
//process 'a' types
}
elseif(record_t ype=='b')
{
//process 'b' types
}
elseif(record_t ype=='c')
{
//process 'c' types
}
}//end loop
}
I can read the data just fine, my problem is that all records are being
treated as 'a' records. Any help would be greatly appreciated.
Thanks
file contains 3 types of records (a,b,c) each has it's own field
definition for the position on the line. Record type is always held in
position 2(php 0,1,2), with a length of 1.
I would like to process each line seperatley, evaluating the record
type, and then taking the appropriate action. Like so:
//open the import file
$import_file = fopen(dirname(_ _FILE__)."/../../data/imports/data.imp",
"r");
//make sure we can read it
if($import_file )
{
//loop to read each line
while (!feof($import_ file))
{
//read line and process accordingly
$line = fgets($import_f ile);
$record_type = substr($line, 2,1);
if($record_type =="a")
{
//process 'a' types
}
elseif(record_t ype=='b')
{
//process 'b' types
}
elseif(record_t ype=='c')
{
//process 'c' types
}
}//end loop
}
I can read the data just fine, my problem is that all records are being
treated as 'a' records. Any help would be greatly appreciated.
Thanks
Comment