Hello,
So i am working on a project for a company where i am taking a (large) CSV file exported from another program, and parsing this data into nice, easy to read graphical data - relatively simple idea.
Here is the problem:
The data in the CSV file contains dollar amounts, and dollar amounts of greater then $999 is in the format: 1,234.00. You might be able to see the problem.
So when i explode the data in the file on commas i get the following (for example):
[1026] => "11
[1027] => 541.00"
the original amount stored in the file was: "11,541.00"
so the explode is splitting this into 2 parts.. but i need just the 1 value.
I tries using preg_replace to only replace commas in between quotes with nothing, but this was just creating a huge mess.
If anyone has any suggestions about how i could better parse this, PLEASE enlighten me!
Thanks,
kris
parsing CSV files question
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: parsing CSV files question
Have you looked a PHP's CSV import functions? They should handle quoted values with ease. I have a class that wraps them for reading delimited files (because Luke wouldn't fix his!
)
(#10850)
Re: parsing CSV files question
Yea,
i tried using str_getcsv()
but when i try this:
Fatal error: Call to undefined function str_getcsv()
at first i thought it might be an extension not enabled in php... but i could not find reference to an extension that supports this.
i tried using str_getcsv()
but when i try this:
Fatal error: Call to undefined function str_getcsv()
at first i thought it might be an extension not enabled in php... but i could not find reference to an extension that supports this.
Re: parsing CSV files question
ahh i found fgetcsv() ...
problem solved, disregard this!
problem solved, disregard this!