Reading in a CSV File

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
irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Reading in a CSV File

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

irishmike2004
Forum Contributor
Posts: 119
Joined: Mon Nov 15, 2004 3:54 pm
Location: Lawrence, Kansas

Thanks Feyd

Post 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?
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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]
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Post Reply