title: Parse EDI file with php / mysql
body: <p>I have a 40K line EDI (fixed length) file that I must parse into a csv. If you know edi you know that each element has its own fixed length.</p>
  
  <p>Im new to parsing EDI and just need a bit of help. My first thought is to set up a table that will hold the element lengths either as an array or as such</p>
  
  <pre><code>Table EDIInfo
  EDI_ID           |  EDI_ElemLengths
  
  1                |  3,22,7s2,30,30,22
  2                |  30,5s2,9s2,3,1,23
  </code></pre>
  
  <p>** the s in the array above denotes a decimal ofter the second place from right.</p>
  
  <p>So once I get this data into the db, Im not sure how to pull it out to apply it to the file that I have located on my server. The file is extensionless at this point, its a simple text file. Id like to parse it into a new file XXXX.csv in the same directly.</p>
  
  <p>Any links to tuts or any help/direction would be greatly appreciated.</p>
  
  <p>If you dont know EDI, its basically a text file with a "record" on each line composed of "elements". Each "element" is allowed a fixed number of characters  on that line even if it does not take up all its allotted space. An element is similar to a field (like a field is defined such as varchar 64, an element is defined by the amount of spaces it is allowed to use in the text file). Elements bump up to one another, there are no delimiters outside of the element space allotment.</p>
  
  <p>Thank you</p>