Page 1 of 1

Reading in a CSV File

Posted: Wed Oct 12, 2005 3:25 pm
by irishmike2004
Hello:

I am doing a presentation in about 2 hours and part of it needs to read in a CSV text file into PHP... can someone tell me the quickest way to do this?

Thanks many times over for your help on this!

Mike

Posted: Wed Oct 12, 2005 3:43 pm
by feyd

Thanks Feyd

Posted: Wed Oct 12, 2005 3:48 pm
by irishmike2004
Yes, I saw the manual entry but I am not very clear on how to get this... the file is very simple...


I need an actual code snippit that reads in my file... here is the file contents right now...

Code: Select all

Currently playing song: "Everywhere" by Michelle Branch on <i>The Spirit Room</i>.
This actually is what is in the text file and I am working on the script it will generate it with commas between artist song album.

The fgetcsv() function page is over my experience though I am not sure if I just copy one of those codes in it will work?

Posted: Wed Oct 12, 2005 3:53 pm
by s.dot
fgetcsv will copy the file into an array, each line an element in the array. then you could explode, or write a couple regexs to get out the information that you want...

in your example, it would produce an array like this

Array (
[0] => Currently playing song: "Everywhere" by Michelle Branch on <i>The Spirit Room</i>.
}

so whatever name you chose for the array, this line would be $array[0]