Php Parsing Newbie coming from Excel
| From: | Mike | Date: | Wed, 23 Apr 2003 15:59:07 +0000 |
| Subject: | Php Parsing Newbie coming from Excel | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-145045@lists.php.net to get a copy of this message | ||
Can someone point me in the right direction. I would like to build a script that can parse a csv or xls file and feedback the info in a
web page as I do not need to store it in a db. I need some suggestions on additional tutorials on php parsing. I can save the file as csv and
I can upload the file to a server but I am having a time at wrapping my brain around php parsing. A small sample of the file is below.
Problem #1: The file is interspersed with empty and multi line records
text strings are delimited by quotes but numbers are not.
Problem #2: The multi line records look like the following:
"Apr 03, 03","BL81RED",4138886,"SPPROCK","PORME","HAILEY,ME ( PORTLAND VALLEY DIST )",,,"Th APR 3.00 00",09:30:00,"ET",16:30:00,1.72,"ALLI",25
,,"OWS",,,,,,,,,,,,
,,,,"BANME","BANGOR,ME( BANGOR ME DIST )",,,"Th APR 3.00 00",10:00:00,"ET",14:00:00,"4+00","AMSD",
,,,,,,,,,,,,,,
,,,,,,,,,,,,"DELA",,
How can I read in or parse only the lines that look like the above and
ignore or remove the lines that have no data or incomplete data.
I want to grab everything from the "Apr 03, 03" field, to the last "DELA" field.
I then want to order or sort the record by the "PORME" field or possibly by a date field.
I am thinking that this will all go into an array of which I will sort and then display in an html table or I would like to give the user the option of sorting or displaying the data per her or his choice.
Can someone please recommend some extensive tutorials on php parsing or provide some detailed parsing examples!
For instance I want to find all the lines and only the lines that begin with "Apr 03, 03" and then collect all the fields up untill but not including the next "Apr 03, 03" and display these as a complete record.
I then want to organize these collections of records based on one of the
fields either Location or Date.
Sorry for such a long post!
Kind regards,
Mike
SAMPLE DATA FROM XLS SPREADSHEET SAVED AS A CSV FILE"
"KIV",,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,"KIV",,"NA","NA",,,,,,,,0,,
,,,,,,,,,,,,,,
,,,,"NA",,,,,,,,"0",,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
"Apr 03, 03","BL81RED",4138886,"SPPROCK","PORME","HAILEY,ME ( PORTLAND VALLEY DIST )",,,"Th APR 3.00 00",09:30:00,"ET",16:30:00,1.72,"ALLI",25
,,"OWS",,,,,,,,,,,,
,,,,"BANME","BANGOR,ME( BANGOR ME DIST )",,,"Th APR 3.00 00",10:00:00,"ET",14:00:00,"4+00","AMSD",
,,,,,,,,,,,,,,
,,,,,,,,,,,,"DELA",,
"Apr 03, 03","BL82PINK",4138886,"SPPROCK","PORME","HAILEY,ME ( PORTLAND VALLEY DIST )",,,"Th APR 3.00 00",09:30:00,"ET",16:30:00,1.72,"ALLI",3
,,"OWS",,,,,,,,,,,,
,,,,"BANME","BANGOR,ME( BANGOR ME DIST )",,,"Th APR 3.00 00",10:00:00,"ET",14:00:00,"4+00","AMSD",
,,,,,,,,,,,,,,
,,,,,,,,,,,,"DELA",,
"Apr 03, 03","FZ1QTBLACK",4137732,"JOHAN","TOLOH","TOLEDO,OH ( TOLEDO LUCAS DIST )",,,"Th APR 3.00 00",10:00:00,"ET",15:30:00,1.72,"FRANC",40
,,"BMF",,,,,,,,,,,,
,,,,"TO","SHAPA( SHARON PA DIST )",,,"Th APR 3.00 00",13:30:00,"ET",17:30:00,"4+00","ALPM",
,,,,,,,,,,,,,,
,,,,,,,,,,,,"MARTI",,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
"CL-600 2A12",,,,,,,,,,,,,,
,,,,,,,,,,,,,,
,,,,,,,,,,,,,,
"Apr 03, 03","FZ1QTBROWN",4239917,"JOHAN","TOLOH","TOLEDO,OH ( TOLEDO LUCAS DIST )",,,"Th APR 3.00 00",10:00:00,"ET",15:30:00,1.72,"FRANC",25
,,"BMF",,,,,,,,,,,,
,,,,"TO","SHAPA( SHARON PA DIST )",,,"Th APR 3.00 00",13:30:00,"ET",17:30:00,"4+00","ALPM",
,,,,,,,,,,,,,,
,,,,,,,,,,,,"MARTI",,