• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Can i use CSV with PHP?

stndn

Golden Member
Helo...
i'm wondering if it's possible to use PHP to access data stored in CSV (comma separated value) functions?

I have a small database (quite small that i don't think i want to export it to mySQL) that i'm using for my CGI scripts.
I'm thinking of migrating some of my PHP scripts to use this same CSV as well.
To avoid having to make changes to the CGI scripts as well, i've decided to just try to have PHP access the CSV "database" somehow..

So, is there a way to have PHP connect to CSV, search for records, fetch data, and close the connection?
If so, what would be the command/function to open the connection and fetch the data?

Thanks.
 
A CSV file is just a text file with lots of data separated by commas. You treat it like a regular text file, reading it line by line and then tokenizing each line. The explode() function will probably come in very handy.

Take a look at PHP.net for documentation.

EDIT: amdfanboy seems to have a better method.
 
hmm... i wonder why it's not included in the php manual that i downloaded...
but anyways, fgetcsv() looks quite promising ...
thanks, amdfanboy -)

and yeah, i know that separating by commas are not a good idea for CSV files...
i was taught to use \0, but i don't know if it's a good idea as well...
(or maybe \0 is used for something else .. i forgot..)

thanks again -)
 
oopss.. i mean:
use \0 to separate fields in text files, not use \0 as separator in comma separated values files ... ,p
 
Back
Top