PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 13th, 2012, 02:08 AM
makenoiz makenoiz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Posts: 18 makenoiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 39 sec
Reputation Power: 0
PHP5 - Parse EDI with PHP/MySql

Hi! 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.

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

Code:
Table EDIInfo
EDI_ID           |  EDI_ElemLengths

1                |  3,22,7s2,30,30,22
2                |  30,5s2,9s2,3,1,23


** the s in the array above denotes a decimal ofter the second place from right.

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.

Any links to tuts or any help/direction would be greatly appreciated.

Reply With Quote
  #2  
Old November 13th, 2012, 07:17 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,875 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 23 h 55 m 3 sec
Reputation Power: 581
If you could clarify a bit more, why do you want to put EDI formatted data into a database? It seems to me that you would parse the EDI data then put the normalized result into the database and/or your csv file.

As for parsing the data, you are correct. You would read each line into an array based on the delimiters and then normalize the data. It is my understanding that there have been numerous attempts to create PHP parsers for EDI but they tend to be abandoned since although the structure of EDI is relatively simple conversion of the data itself is unique to each data file.
__________________
There are 10 kinds of people in the world. Those that understand binary and those that don't.

Reply With Quote
  #3  
Old November 14th, 2012, 12:59 AM
makenoiz makenoiz is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2010
Posts: 18 makenoiz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 39 sec
Reputation Power: 0
The EDI data itself will not be in the DB. The Element lengths will.
My thought (thought about it in my sleep and going to try it tonite) is this.
1) read each segment as a string
2) explode the segment based on the value of each element length that I have stored in a mysql table
3) strip blank spaces from the exploded results (element data does not always take up the entire element space) and replace with a delimiter like '^'
4) save as a delimited file.
Does that seem logically sound?

Thank you for your input.

Reply With Quote
  #4  
Old November 14th, 2012, 07:08 AM
gw1500se gw1500se is online now
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Jul 2003
Posts: 2,875 gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level)gw1500se User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 1 Year 1 Week 5 Days 23 h 55 m 3 sec
Reputation Power: 581
Sounds fine to me.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP5 - Parse EDI with PHP/MySql

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap