Search Webmaster Help and Solution

[RESOLVED] Implode() going goofy or am I?

Trying to parse a fixed-width text file into an array for each line.
All Im getting is an empty array with 10 empty elements when I should be getting
an array with 10 arrays of 5 elements.
Note: Im ignoring the last three columns.

I also have to manipulate the $pn variable, that is why Im not just using the array_values function as input to the $fields_order array.

PHP Code: $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:
PHP Code: 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
Trying to parse a fixed-width text file into an array for each line.
All Im getting is an empty array with 10 empty elements when I should be getting
an array with 10 arrays of 5 elements.
Note: Im ignoring the last three columns.

I also have to manipulate the $pn variable, that is why Im not just using the array_values function as input to the $fields_order array.

PHP Code: $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:
PHP Code: 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

View Complete Thread with Replies

Related Items

Query failed: connection to localhost:3354 failed (errno=111, msg=Connection refused).