glenelkins Posted August 2, 2006 Share Posted August 2, 2006 Im writing a script that should be simple but its becoming a pain. It reads a CSV file line by line, then splits the lines into an array (seperated by commas)Here is the code[code]<? /* CSV to MYSQL conversion utitliy */ /* Author: Glen Elkins */ /* 08/2006 */ // Set variables define ("APP_PATH","."); define ("CSV_FOLDER","/csv/"); define ("CSV_FILE","contacts.csv"); // Open The File $csv_data = file(APP_PATH.CSV_FOLDER.CSV_FILE); // Just read the first line to test echo $csv_data[0]; - displays the first line: uid,email,valid,optin,source $line = $csv_data[0]; $exploded = explode(",",$line); echo $exploded[0]; - should display uid but displays uid,email,valid,optin,source ?>[/code]Can anyone see the problem? Quote Link to comment Share on other sites More sharing options...
nogray Posted August 2, 2006 Share Posted August 2, 2006 shouldn't "," be a "," Quote Link to comment Share on other sites More sharing options...
glenelkins Posted August 2, 2006 Author Share Posted August 2, 2006 THat does not work either Quote Link to comment Share on other sites More sharing options...
glenelkins Posted August 2, 2006 Author Share Posted August 2, 2006 oh! it does not. for some reason that didnt work before ... Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted August 2, 2006 Share Posted August 2, 2006 fgetcsv() will save you tons of time Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.