//We'll need this function soon:
function explode_records($string)
{ //String contains a single record. Separate it into an array of fields.
$fields=explode('<eof>',$string);
foreach($fields as $field)
{ preg_match('(.+): (.+)$', $field, $matches);
$array[$matches[1]]=$matches[2];
}
return $array;
}
//Inhale the entire file into a big string,
$string=fread($file,filesize($file));
fclose($file); // Funny, I don't remember opening it :-)
//We'll kill off newlines that would only cause trouble later
$string=str_replace("\n",'',$string);
//explode it into an array on "<eor>"
$array=explode('<eor>',$string);
//You now have an array of records.
//Use the array_map function:
$array = array_map($array, 'explode_records');
With the input
$DocID:2341234123412341234123412341234<eof>
$Version: 15<eof>
MasNbr: 1153<eof>
Vendor: 3COM<eof>
SKU: 128965<eof>
CCode: 05<eof>
SCCode: 21<eof>
MCodes: PERP<eof>
<eor>
The result should be (modulo booboos on my part):
$array['$DocID']='2341234123412341234123412341234';
$array['$Version']='15';
...
$array['MCodes']='PERP';
//I guess you'll want an SQL INSERT query:
//First, the field names (assuming that there are already columns with suitable names in mytable):
$keys=join(',',array_keys($array));
//And their values
$values=join(',',array_values($array));
$sql="INSERT INTO mytable ($keys)VALUES($values)";
}