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? Link to comment https://forums.phpfreaks.com/topic/16385-cannot-crack-this/ Share on other sites More sharing options...
nogray Posted August 2, 2006 Share Posted August 2, 2006 shouldn't "," be a "," Link to comment https://forums.phpfreaks.com/topic/16385-cannot-crack-this/#findComment-68182 Share on other sites More sharing options...
glenelkins Posted August 2, 2006 Author Share Posted August 2, 2006 THat does not work either Link to comment https://forums.phpfreaks.com/topic/16385-cannot-crack-this/#findComment-68185 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 ... Link to comment https://forums.phpfreaks.com/topic/16385-cannot-crack-this/#findComment-68186 Share on other sites More sharing options...
ryanlwh Posted August 2, 2006 Share Posted August 2, 2006 fgetcsv() will save you tons of time Link to comment https://forums.phpfreaks.com/topic/16385-cannot-crack-this/#findComment-68190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.