Trying to parse a fixed-width text file into an array for each line.
All I'm getting is an empty array with 10 empty elements when I should be getting
an array with 10 arrays of 5 elements.
Note: I'm ignoring the last three columns.
I also have to manipulate the $pn variable, that is why I'm not just using the array_values function as input to the $fields_order array.
$fp=@fopen($fileName,"r") or die ("Can not open file.");
while ($line=@fgets($fp)){
list($pn, $apn, $cc, $q, $desc, $x, $y, $z)=array_values(unpack("A25pn/A11apn/A11cc/A10q/A13desc/A13x/A11y/A18z",$line));
$fields_order[] = implode(',', $pn.','.$apn.','.strtoupper($cc).','.$q.','.$desc);
}
print_r($fields_order);
Data is as follows:
5701C60-530136-9 605301369 NS 2 HANDLE EABE 1 000000000Y
5701CA35AIWBK NS 4 HOOD EAMISC 1244132 000000000Y
5701C77982-002 77982002 SV 1 STRAP EAPI 5 000000000Y
5701C101-306 NS 1 PLATE EACS 1241908 000000000Y
5701C763-731 763731 NE 3 WASHER-MIN ORD 100 EEAPI 33 000000000Y
5701C763-731 763731 NS 2 WASHER-MIN ORD 100 EEAPI 33 000000000Y
5701C2524648-G 2524298-10 AR 1 SERVO FUEL INJECT. EAMISC 34 000000000Y
5701C2524648-G RSA10ED1 AR 1 SERVO FUEL INJECT. EAMISC 34 000000000Y
5701C2524648-G 2524648G AR 1 SERVO FUEL INJECT. EAMISC 34 000000000Y
5701CLBV11S025-S90 AR 1 FITTING EAMISC 1244126 000000000Y