Spliting from CSV

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
eyriquewong
Forum Newbie
Posts: 2
Joined: Sun Sep 26, 2010 11:57 pm

Spliting from CSV

Post by eyriquewong »

hi,

i have a csv file, the data is something as below:
1/19/2010,book_1,14,"67,333",5
2/19/2010,book_2,15,"15,123",6
how do i make it into an array?

Here's how i come so far
$temp_array = explode("\n",read_file('my.csv'));
foreach($temp_array as $lines){
//echo $lines;
list($date,$booktitle,$id,$total_hits,$price) = explode($lines);
}
But it seems that it had split the hits comma value as well... is there any way to ignore the comma inside a double quote?

Thanks
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Spliting from CSV

Post by requinix »

fopen + fgetcsv in a loop + fclose.
Post Reply