• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

Replace extra commas (,) from csv in importer

Good Morning experts,

I have run into a problem when importing a csv file that has extra commas(,) in a field and therefore when i go to import the csv it skips all the rows where there are extra commas(,) as it thinks there are unequal amounts of fields.
I have no control over the format of the csv file so changing it manually is not an option. I have code that skips the first row and other row that only includes 0's.

Here is the csv data:

Category,Brand,Manufacturer code,VST Product code,Description,Warranty,Price,Web Link,Pic URL,Product name,ETA (1 instock/0 out stock,Date
0,0,0,0,0,0,0,0,0,0,0,
Seagate IDE HDD,Seagate,ST380215A,ST380215A,"80GB, 7200rpm 2mb cache 3,5"" HDD",3 years,75,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_IDE.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Barracuda_7200-8.jpg,Seagate 80GB 2mb cache,1,
Seagate IDE HDD,Seagate,ST3160815A,ST3160815A,"160GB, 7200rpm 8mb cache 3.5"" HDD",3 years,83,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_IDE.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Barracuda_7200-8.jpg,Seagate 160GB 2mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,seagate,st31500341as,st31500341as,"1500GB, 7200rpm, NCQ SATA 3G 3.5"" 32MB Cache",3 years,265,0,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,"1500GB, 7200rpm, NCQ SATA 3G 3.5"" 32MB Cache",1,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SATA 3G HDD,Seagate,ST380815AS,ST380815AS,"80GB, 7200rpm, NCQ SATA 3G 3.5"" 8MB Cache",3 years,67,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 80GB SATA 3G 8mb cache,1,
Seagate SATA 3G HDD,Seagate,ST3160815AS,ST3160815AS,"160GB, 7200rpm, NCQ SATA 3G 3.5"" 8MB Cache",3 years,73,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 160GB SATA 3G 8mb cache,1,
Seagate SATA 3G HDD,Seagate,ST3250410AS,ST3250410AS,"250GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB Cache",3 years,87,0,0,Seagate 250GB SATA 3G 8mb cache,1,
Seagate SATA 3G HDD,Seagate,ST3250310AS,ST3250310AS,"250GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB Cache",3 years,84,0,0,Seagate 250GB SATA 3G 8mb cache,1,
Seagate SATA 3G HDD,Seagate,ST3320613AS,ST3320613AS,"320GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB Cache",3 years,91,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 320GB SATA 3G 16mb cache,1,
Seagate SATA 3G HDD,Seagate,ST3500320AS,ST3500320AS,"500GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB Cache",3 years,113,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 400GB SATA 3G 16mb cache,1,
Seagate SATA 3G HDD,Seagate,ST3750330AS,ST3750330AS,"750GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB Cache",3 years,174,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 500GB SATA 3G 16mb cache,1,
Seagate SATA 3G HDD,Seagate,ST31000340AS,ST31000340AS,"1000GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB Cache",3 years,194,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 750GB SATA 3Gb/s 16mb cache,1,
Seagate Barracuda ES SATA 3G HDD,Seagate,ST3500320NS,ST3500320NS,"500GB, 7200rpm, NCQ SATA 3G 3.5"" 32MB Cache",3 years,199,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 500GB SATA 3Gb/s 32mb cache,1,
Seagate Barracuda ES SATA 3G HDD,Seagate,ST3750330NS,ST3750330NS,"750GB, 7200rpm, NCQ SATA 3G 3.5"" 32MB Cache",3 years,295,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_barracuda_SATA.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Cuda_7200_9_SATA_500GB.jpg,Seagate 750GB SATA 3Gb/s 32mb cache,1,
Seagate Barracuda ES2 SATA 3G HDD,Seagate,ST31000340NS,ST31000340NS,"1TB, 7200rpm, NCQ SATA 3G 3.5"" 32MB",3 years,325,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_NL35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/DB35.jpg,Seagate Barracuda ES2 1TB 32mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
Seagate Barracuda ES SATA 3G HDD,Seagate,ST3750640NS,ST3750640NS,"750GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB",3 years,271,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_NL35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/DB35.jpg,Seagate Barracuda ES 750GB 16mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SV35 SATA HDD,Seagate,ST31000340SV,ST31000340SV,"1TB, 7200rpm, NCQ SATA 3G 3.5"" 32MB",3 years,241,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_SV35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/sv35.jpg,Seagate SV35 7200.2 1TB SATA 3G 32mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SV35 SATA 3G HDD,Seagate,ST3250310SV,ST3250310SV,"250GB, 7200rpm, NCQ SATA 3G 3.5"" 8MB",3 years,91,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_SV35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/sv35.jpg,Seagate SV35 7200.2 250GB SATA 3G 8mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SV35 SATA 3G HDD,Seagate,ST3320620SV,ST3320620SV,"320GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB",3 years,119,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_SV35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/sv35.jpg,Seagate SV35 7200.2 320GB SATA 3G 16mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SV35 SATA 3G HDD,Seagate,ST3500320SV,ST3500320SV,"500GB, 7200rpm, NCQ SATA 3G 3.5"" 16MB",3 years,123,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_SV35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/sv35.jpg,Seagate SV35 7200.2 500GB SATA 3G 16mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SV35 SATA 3G HDD,Seagate,ST3750330SV,ST3750330SV,"750GB, 7200rpm, NCQ SATA 3G 3.5"" 32MB",3 years,220,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_SV35.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/sv35.jpg,Seagate SV35 7200.2 750GB SATA 3G 16mb cache,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
Seagate Notebook HDD,Seagate,ST9250827AS,ST9250827AS,"250GB, 8MB, 5400rpm, 2.5"" SATA HDD",3 years,113,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 250GB 5400rpm 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9120822A,ST9120822A,"120GB, 8MB, 5400rpm, 2.5"" IDE HDD",3 years,100,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 120GB 5400rpm 2.5"" IDE HDD",1,
Seagate Notebook HDD,Seagate,ST9160821A,ST9160821A,"160GB, 8MB, 5400rpm, 2.5"" IDE HDD",3 years,114,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 160GB 5400rpm 2.5"" IDE HDD",0,
0,0,0,0,0,0,0,0,0,0,0,
Seagate Notebook HDD,Seagate,ST9320320AS,ST9320320AS,"320GB, 8MB, 5400rpm, 2.5"" SATA HDD ",3 years,123,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 320GB 5400rpm 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9120817AS,ST9120817AS,"120GB, 8MB, 5400rpm, 2.5"" SATA HDD ",3 years,82,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 120GB 5400rpm 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9160310AS,ST9160310AS,"160GB, 8MB, 5400rpm, 2.5"" SATA HDD ",3 years,97,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 160GB 5400rpm 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9120823AS,ST9120823AS,"120GB, 8MB,  7200rpm, 2.5"" SATA HDD",3 years,111,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_SATA.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 120GB, 8MB,  7200rpm, 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9160823AS,ST9160823AS,"160GB, 8MB,  7200rpm, 2.5"" SATA HDD",3 years,115,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_SATA.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 160GB, 8MB,  7200rpm, 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9200420AS,ST9200420AS,"200GB, 8MB,  7200rpm, 2.5"" SATA HDD",3 years,121,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_SATA.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 200GB, 8MB,  7200rpm, 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9320421AS,ST9320421AS,"320GB, 8MB, 7200rpm, 2.5"" SATA HDD ",3 years,147,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 320GB 7200rpm 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9250421AS,ST9250421AS,"250GB, 8MB, 7200rpm, 2.5"" SATA HDD",3 years,125,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"Seagate 250GB 7200rpm 2.5"" SATA HDD",1,
Seagate Notebook HDD,Seagate,ST9500325AS,ST9500325AS,"500GB, 8MB, 5400rpm, 2.5"" SATA HDD",3 years,184,http://www.vst.co.nz/harddrive/2.5%20harddrive/Seagate_momentus_ide.html,http://www.vst.co.nz/harddrive/2.5%20harddrive/img/Momentus_5400_3.jpg,"500GB, 8MB, 5400rpm, 2.5"" SATA HDD",1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,ST3300007LC,ST3300007LC,"300GB, 10K rpm, 3.5"" SCSI SCA",0,"1,071",http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_cheetah.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Cheetah_10K-7.jpg,0,0,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SCSI HDD,Seagate,ST373455LC,ST373455LC,"73GB, 15K rpm, 3.5"" SCSI SCA",5 years,364,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_cheetah.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Cheetah_10K-7.jpg,Seagate 73GB 15Krpm SCSI,1,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SCSI HDD,Seagate,ST3300656SS,ST3300656SS,"300GB, 15K rpm, 3.5"" SCSI SCA",5 years,853,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_cheetah.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Cheetah_10K-7.jpg,"300GB, 15K rpm, 3.5"" SCSI SCA",1,
Seagate SCSI HDD,Seagate,ST373455SS,ST373455SS,"73GB, 15K rpm, 3.5"" Serial Attach SCSI",5 years,364,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_cheetah.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Cheetah_10K-7.jpg,"73GB, 15K rpm, 3.5"" Serial Attach SCSI",1,
Seagate SCSI HDD,Seagate,ST3146855LC,ST3146855LC,"146GB, 15K rpm, 3.5"" SCSI SCA",5 years,496,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_cheetah.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Cheetah_10K-7.jpg,"146GB, 15K rpm, 3.5"" SCSI SCA",1,
0,0,0,0,0,0,0,0,0,0,0,
Seagate SCSI HDD,Seagate,ST3146356SS,ST3146356SS,"146GB, 15K rpm, 3.5"" Serial Attach SCSI",5 years,485,http://www.vst.co.nz/harddrive/3.5%20harddrive/seagate_cheetah.html,http://www.vst.co.nz/harddrive/3.5%20harddrive/img/Seagate_Cheetah_10K-7.jpg,"146GB, 15K rpm, 3.5"" Serial Attach SCSI",1,
CAVIAR,WESTERN DIGITAL ,WD5000AAKB,WD5000AAKB,CAVIAR 7200 500GB 8M PATA  ,3,156,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 500GB 8M PATA  ,1,
CAVIAR,WESTERN DIGITAL ,WD800JB,WD800JB,CAVIAR 7200 80GB 8M PATA  ,3,80,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 80GB 8M PATA  ,1,
CAVIAR,WESTERN DIGITAL ,WD1600AAJB,WD1600AAJB,CAVIAR 7200 160GB 8M PATA  ,3,89,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 160GB 8M PATA  ,1,
CAVIAR,WESTERN DIGITAL ,WD2500AAJB,WD2500AAJB,CAVIAR 7200 250GB 8M PATA  ,3,114,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 250GB 8M PATA  ,1,
CAVIAR,WESTERN DIGITAL ,WD3200AAJB,WD3200AAJB,CAVIAR 7200 320GB 8M PATA  ,3,124,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 320GB 8M PATA  ,1,
CAVIAR,WESTERN DIGITAL ,WD10EADS,WD10EADS,CAVIAR 7200 1TB 32M SATA 2,3,208,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 1TB 32M SATA 2,1,
CAVIAR BLACK,WESTERN DIGITAL ,WD1001FALS,WD1001FALS,CAVIAR 7200 1TB 32M SATA 2,3,229,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 1TB 32M SATA 2,1,
0,0,0,0,0,0,0,0,0,0,0,
CAVIAR,WESTERN DIGITAL ,WD800AAJS,WD800AAJS,CAVIAR 7200 80GB 2M SATA 2 ,3,75,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 80GB 2M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD5000AACS,WD5000AACS,CAVIAR 7200 500GB 16M SATA 2 ,3,119,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 500GB 16M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD1600AAJS,WD1600AAJS,CAVIAR 7200 160GB 8M SATA 2 ,3,80,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 160GB 8M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD2500AAJS,WD2500AAJS,CAVIAR 7200 250GB 8M SATA 2 ,3,87,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 250GB 8M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD2500AAKS,WD2500AAKS,CAVIAR 7200 250GB 16M SATA 2 ,3,90,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 250GB 16M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD3200AAKS,WD3200AAKS,CAVIAR 7200 320GB 16M SATA 2 ,3,95,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 320GB 16M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD6400AAKS,WD6400AAKS,CAVIAR 7200 6400GB 16M SATA 2 ,3,135,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 6400GB 16M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD5000AAKS,WD5000AAKS,CAVIAR 7200 500GB 16M SATA 2 ,3,120,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 500GB 16M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD7500AACS,WD7500AACS,CAVIAR 7200 750GB 16M SATA 2 ,3,179,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 750GB 16M SATA 2 ,1,
CAVIAR,WESTERN DIGITAL ,WD10EACS,WD10EACS,CAVIAR 7200 1TB 16M SATA 2,3,204,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR 7200 1TB 16M SATA 2,1,
CAVIAR,WESTERN DIGITAL ,WD2502ABYS,WD2502ABYS,CAVIAR R/E 7200 250GB 16MB SATA 2,3,122,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR R/E 7200 250GB 16MB SATA 2,1,
CAVIAR,WESTERN DIGITAL ,WD7500AYYS,WD7500AYYS,CAVIAR R/E 7200 750GB 16MB SATA 2,3,284,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR R/E 7200 750GB 16MB SATA 2,1,
CAVIAR,WESTERN DIGITAL ,WD3202ABYS,WD3202ABYS,CAVIAR R/E 7200 320GB 16MB SATA 2,3,137,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR R/E 7200 320GB 16MB SATA 2,1,
CAVIAR,WESTERN DIGITAL ,WD5002ABYS,WD5002ABYS,CAVIAR R/E 7200 500GB 16MB SATA 2,3,168,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,CAVIAR R/E 7200 500GB 16MB SATA 2,1,
Scorpio Black,WESTERN DIGITAL ,WD3200BEKT,WD3200BEKT,Scorpio 7200 320GB 16 MB SATA,3,151,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,Scorpio 7200 320GB 16 MB SATA,1,
RAPTOR,WESTERN DIGITAL ,WD1500HLFS,WD1500HLFS,"RAPTOR 10,000 150GB 16 MB SATA 1",5,382,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,"RAPTOR 10,000 150GB 16 MB SATA 1",1,
Scorpio Black,WESTERN DIGITAL ,WD2500BEKT,WD2500BEKT,Scorpio 7200 250GB 16 MB SATA,3,149,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,Scorpio 7200 250GB 16 MB SATA,1,
Scorpio,WESTERN DIGITAL ,WD800BEVE,WD800BEVE,"Scorpio 5,400 80GB 8 MB PATA",3,99,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 80GB 8 MB PATA",1,
Scorpio,WESTERN DIGITAL ,WD5000BEVT,WD5000BEVT,"Scorpio 5,400 500GB 8 MB SATA",3,208,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 500GB 8 MB SATA",1,
Scorpio,WESTERN DIGITAL ,WD1600BEVE,WD1600BEVE,"Scorpio 5,400 160GB 8 MB PATA",3,126,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 160GB 8 MB PATA",1,
Scorpio,WESTERN DIGITAL ,WD2500BEVE,WD2500BEVE,"Scorpio 5,400 250GB 8 MB PATA",3,160,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 250GB 8 MB PATA",1,
Scorpio,WESTERN DIGITAL ,WD1200BEVS,WD1200BEVS,"Scorpio 5,400 120GB 8 MB SATA",3,86,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 120GB 8 MB SATA",1,
Scorpio,WESTERN DIGITAL ,WD1600BEVS,WD1600BEVS,"Scorpio 5,400 160GB 8 MB SATA",3,99,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 160GB 8 MB SATA",1,
Scorpio,WESTERN DIGITAL ,WD2500BEVS,WD2500BEVS,"Scorpio 5,400 250GB 8 MB SATA",3,116,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 250GB 8 MB SATA",1,
Scorpio,WESTERN DIGITAL ,WD3200BEVT,WD3200BEVT,"Scorpio 5,400 320GB 8 MB SATA",3,135,http://www.vst.co.nz/harddrive/2.5%20harddrive/WD_Scorpio_ide.html,0,"Scorpio 5,400 320GB 8 MB SATA",1,
RAPTOR,WESTERN DIGITAL ,WD3000GLFS,WD3000GLFS,"RAPTOR 10,000 300GB 16 MB SATA 1",5,555,http://www.vst.co.nz/harddrive/3.5%20harddrive/WD3-5-inch.html,0,"RAPTOR 10,000 150GB 16 MB SATA 1",1,
Accusys SATA Raid,Accusys,ACS75170,IR009,SATA to SATA raid kit RAID 1,2 years,520,http://www.vst.co.nz/storage%20solution/accusys/ACS75170/ACS75170.html,http://www.vst.co.nz/storage%20solution/accusys/ACS75170/img/acs_7500_mini05.gif,SATA to SATA raid kit RAID 1,1,
Accusys SATA Raid,Accusys,ACS75170(BLK),IR010,SATA to SATA raid kit RAID 1,2 years,520,http://www.vst.co.nz/storage%20solution/accusys/ACS75170/ACS75170.html,http://www.vst.co.nz/storage%20solution/accusys/ACS75170/img/acs_7500_mini05.gif,SATA to SATA raid kit RAID 1,1,
Accusys SATA Raid,Accusys,ACS76510(Blk),IR011,SATA/SATA  raid kit RAID1 backup,2 years,580,0,0,SATA/SATA  raid kit RAID1 backup,0,
Accusys SATA Raid,Accusys,ACS76130,IR012,"SATA/SATA  raid kit RAID 0, 5",2 years,620,0,0,"SATA/SATA  raid kit RAID 0, 5",1,
Accusys SATA Raid (BLK),Accusys,ACS76510(white),IR013,SATA/SATA  raid kit RAID1 backup (BLK),2 years,580,0,0,SATA/SATA  raid kit RAID1 backup (BLK),1,
Accusys IDE Raid,Accusys,ACS-75130 Tray,TR001,Accusys IDE Tray for ACS 7500,2 years,80,0,0,Accusys IDE Tray for ACS 7500,1,
Accusys IDE Raid,Accusys,ACS7500A(BLK),TR003,Accusys IDE Tray for ACS 7500,2 years,80,0,0,Accusys IDE Tray for ACS 7500,0,
Accusys IDE Raid,Accusys,ACS-6100 Tray,TR004,Accusys IDE Tray for ACS 6100,2 years,499,0,0,Accusys IDE Tray for ACS 6100,1,
Accusys SATA Raid,Accusys,ACS75170,TR006,Accusys SATA Tray for ACS 75170,2 years,90,0,0,Accusys SATA Tray for ACS 75170,1,
Accusys SATA Raid,Accusys,ACS75170(BLK),TR007,Accusys SATA Tray for ACS 75170,2 years,90,0,0,Accusys SATA Tray for ACS 75170,1,
Accusys IDE Raid,Accusys,Acuta 4,IR005 ,"Hardware RAID level 0, 5, 0+1, 5 + spare by dip switch setting",1 years,"1,683",http://www.vst.co.nz/storage%20solution/accusys/Acuta4/acuta4.html,http://www.vst.co.nz/storage%20solution/accusys/Acuta4/img/acuta4.jpg,Acuta 4 ,1,
Accusys IDE Raid,Accusys,ACS Key,KY001 ,Spare Key,2 years,5,0,0,Spare Key,1,
NAS,Synology,DS108j,SS026,Synology Diskstation NAS DS108J SATA (HDD not included),1 years,321,0,http://www.vst.co.nz/storage%20solution/synology/DS106e/img/106e.jpg,Synology Diskstation NAS DS-108J,1,
NAS,Synology,DS107e,SS016,Synology Diskstation NAS DS107e SATA (HDD not included),1 years,606,http://www.vst.co.nz/storage%20solution/synology/DS107e/ds107e.html,http://www.vst.co.nz/storage%20solution/synology/DS106e/img/106e.jpg,Synology Diskstation NAS DS-107e,1,
NAS,Synology,DS207+,SS024,Synology Diskstation NAS DS207+ SATA (HDD not included),1 years,"1,084",http://www.vst.co.nz/storage%20solution/synology/DS207/ds207.html,http://www.vst.co.nz/storage%20solution/synology/DS106e/img/106e.jpg,Synology Diskstation NAS DS-207,1,
NAS,Synology,CS407e,SS018,Synology Diskstation NAS CS407e SATA (HDD not included),1 years,496,http://www.vst.co.nz/storage%20solution/synology/CS407e/CS-407e.html,http://www.vst.co.nz/storage%20solution/synology/DS106e/img/106e.jpg,Synology Diskstation NAS DS-407e,1,
NAS,Synology,DS207,SS017,Synology Diskstation NAS DS207 SATA (HDD not included),1 years,"1,700",http://www.vst.co.nz/storage%20solution/synology/DS207/ds207.html,http://www.vst.co.nz/storage%20solution/synology/DS106e/img/106e.jpg,Synology Diskstation NAS DS-207,1,
NAS,Synology,RS407,SS020,Synology Diskstation NAS RS407 SATA (HDD not included),1 years,"3,376",http://www.vst.co.nz/storage%20solution/synology/RS407/RS-407.html,http://www.vst.co.nz/storage%20solution/synology/DS106e/img/106e.jpg,Synology Diskstation NAS RS-407,1,
NAS,Synology,RS408RP,SS028,Synology Diskstation NAS DS207 SATA (HDD not included),1 years,"2,785",http://www.vst.co.nz/storage%20solution/synology/RS408RP/RS-408RP.html,,Synology Diskstation NAS DS-207,0,
NAS,Synology,RS408,SS027,Synology Diskstation NAS RS407 SATA (HDD not included),1 years,"2,080",http://www.vst.co.nz/storage%20solution/synology/RS408/RS-408.html,,Synology Diskstation NAS RS-407,0,
NAS,Synology,DS508,SS029,Synology Diskstation NAS RS407 SATA (HDD not included),1 years,462,http://www.vst.co.nz/storage%20solution/synology/DS508/CS508.html,,Synology Diskstation NAS RS-407,0,
NAS,Synology,DS107+  R2,SS025,Synology Diskstation NAS DS107+ R2 SATA (HDD not included),1 years,405,,,Synology Diskstation NAS DS107+ R2 SATA (HDD not included),1,
EXTERNAL CASES,VST,"Fire Wire Connection External Case for 2.5"" Drive",EC058,"2.5"" USB 2   CASE PATA",1 year,16,0,0,"2.5"" USB2.0 CASE",1,
EXTERNAL CASES,VST,"Databank 2.5"" USB Case",EC012,"Databank 2.5"" USB Case",1 year,20,0,0,VST DATABANK Case ,1,
EXTERNAL CASES,WELLAND,"Sarotech 2.5 "" one push backup & write protection enclosure",EC061,"Welland 2.5"" USB 2 Case PATA",1 year,17,0,0,Welland enclosure,0,
EXTERNAL CASES,WELLAND,"Sarotech 2.5 "" one push backup & write protection enclosure",EC060,"Welland 2.5"" USB 2 Case SATA",1 year,32,0,0,Welland enclosure,0,
EXTERNAL CASES,TeraPlus,"TeraPlus 2.5"" HDD enclosure PATA",EC035,"TeraPlus 2.5"" HDD enclosure PATA",1 year,11,0,0,"TeraPlus 2.5"" HDD enclosure PATA",1,
EXTERNAL CASES,VST,"Sarotech 3.5"" one push back up & write protection enclosure",EC059,"3.5"" USB2 CASE PATA",1 year,28,0,0,"3.5"" USB 2.0 CASE",1,
EXTERNAL CASES,MacPower,"Fire Wire Connection External Case for 3.5"" Drive",EC010,"Fire Wire Connection External Case for 3.5"" Drive",1 year,140,0,0,"Ice Cube 3.5"" FIREWIRE case ",1
EXTERNAL CASES,WELLAND,"TeraPlus 3.5"" HDD enclosure PATA",EC062,"Welland 3.5"" USB 2 CASE SATA",1 year,44,0,0,Welland enclosure,1
EXTERNAL CASES,NetDisk,NetDisk,EC039,"NetDisk 3.5"" External Enclosure with LAN & USB interface",1 year,107,http://www.vst.co.nz/storage%20solution/enclosure/NetDisk/Netdisk.html,0,"NetDisk 3.5"" External Enclosure with LAN & USB interface",1
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
0,0,0,0,0,0,0,0,0,0,0
Power Supply,Hyena,ATX 300W,ATX300,ATX 300W Power supply,1 year,30,http://www.vst.co.nz/accessory/powersupply/powersupply.html,http://www.vst.co.nz/accessory/powersupply/img/powersupply.jpg,ATX 300W power supply,1
Power Supply,Hyena,ATX 350W,ATX350,ATX 350W Power supply,1 year,40,http://www.vst.co.nz/accessory/powersupply/powersupply.html,http://www.vst.co.nz/accessory/powersupply/img/powersupply.jpg,ATX 350W power supply,1
ME1 Emprex HD Media Enclosure,BTC,ME1,MP021,ME1 Emprex HD Media Enclosure,1 Year,180,http://www.vst.co.nz/multimedia/HomeTheatre/multimedia%20player/ME1.html,http://www.vst.co.nz/multimedia/HomeTheatre/multimedia%20player/ME1.html,ME1 Emprex HD Media Enclosure,1
MR1 Emprex HD Media Center 320Gb,BTC,MR1,MP023,MR1 Emprex HD Media Center 320Gb,1 Year,480,http://www.vst.co.nz/multimedia/HomeTheatre/multimedia%20player/MR1.html,http://www.vst.co.nz/multimedia/HomeTheatre/multimedia%20player/MR1.html,MR1 Emprex HD Media Center 320Gb,1
Media Player,Sarotech,DVP-570S,MP024,"DVP-570S Sarotech 3.5"" SATA Multimedia Player, Network, Full HDTV",1 Year,305,,,Sarotech DVP-570S,1

Here is the import code i use below.
<?php
 
if(!file_exists($csvfile)) {
	echo "File not found. Make sure you specified the correct path.\n";
	exit;
}
 
$file = fopen($csvfile,"r");
 
if(!$file) {
	echo "Error opening data file.\n";
	exit;
}
 
$size = filesize($csvfile);
 
if(!$size) {
	echo "File is empty.\n";
	exit;
}
 
$csvcontent = fread($file,$size);
 
fclose($file);
 
$con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
@mysql_select_db($databasename) or die(mysql_error());
 
$lines = 0;
$queries = "";
$linearray = array();
 
foreach(split($lineseparator,$csvcontent) as $line) {
 
	$lines++;
 
	$line = trim($line," \t");
	
	$line = str_replace("\r","",$line);
		
	/************************************
	This line escapes the special character. remove it if entries are already escaped in the csv file
	************************************/
	$line = str_replace("'","\'",$line);
	/*************************************/
	/************************************
	This line escapes the special character. remove it if entries are already escaped in the csv file
	************************************/
	$line = str_replace('"','',$line);
	/*************************************/
	
	$linearray = explode($fieldseparator,$line);	
	
	if(trim($linearray[0]) == '0')   # ignore blank line
 	 	continue;
	if(trim($linearray[0]) == 'Category')  # ignore blank line
  		continue;
	
	$linemysql = implode("','",$linearray);	
 
	if($addauto)
		$query = "insert into $databasetable values('$linemysql','0','1','vst','2844','','','')";
	else
		$query = "insert into $databasetable values('$linemysql')";
	
	$queries .= $query . "\n";
 
	@mysql_query($query);
 
}
 
@mysql_close($con);
 
if($save) {
	
	if(!is_writable($outputfile)) {
		echo "File is not writable, check permissions.\n";
	}
	
	else {
		$file2 = fopen($outputfile,"w");
		
		if(!$file2) {
			echo "Error writing to the output file.\n";
		}
		else {
			fwrite($file2,$queries);
			fclose($file2);
			}
		}
}

Open in new window

0
nwteam
Asked:
nwteam
  • 2
  • 2
1 Solution
 
Hube02Commented:
I would suggest that rather than building your own function to parse the contents of a csv file that you should try using fgetcsv()

http://us3.php.net/manual/en/function.fgetcsv.php

This function is designed to retrieve the contents of a CSV file and returns one line of the file at a time and puts the line into an array.
0
 
Ionut A. TudorPHP ProgrammerCommented:
replace this:
$csvcontent = fread($file,$size);
with this
$csvcontent = preg_replace('/(,{2,})/im', ',',  fread($file,$size));
Also i see you have an undefined variable $lineseparator, be sure to set it. Good luck
0
 
nwteamAuthor Commented:
@ Hube02

Thank your for your input i would very rather use the existing code as this is a feed from a supplier and i have many other csv files that i ahve used with the same code (modifying to the needs of the csv). I will use the fgetcsv function if it proves to be to hard to modify this code.

@al3cs12

I tried your code and it did not insert into the table.

0
 
nwteamAuthor Commented:
Thanks
0
 
Hube02Commented:
Follow up.

fgetcsv usually does a very good job. CSV files are usually pretty consistent, comma seperated, quotes around data that contain special characters, or commas.

Commas in data is where you current code is having the problem. I is possible to construct a regular expression to weed out this data, but the code would be much more complicated. I would suggest that you make sure that all the data has the same number of columns after retrieval. While most applications output CSV files in a format that insures all rows have the same number of data columns, not all comply with this.

Here is a simple funtion I use to get contents into an array and it makes sure all rows are the same length. It returns a multidimensional array.



  function ReadCSV($file) {
    // this function will read a csv file in and return a multidimensional array
    // $file is path to the file to read
    $csvArray = array();
    // max_cols holds the highest number of columns in the csv
    $max_cols = 0;
    if ($handle = @fopen($file, 'r')) {
      while (($data = fgetcsv($handle, 2000)) !== false) {
        $num_cols = count($data);
        if ($num_cols > $max_cols) {
          $max_cols = $num_cols;
        }
        $csvArray[] = $data;
      }
      fclose($handle);
      // check that all lines contain the same number of columns
      for($i=0; $i<count($csvArray); $i++) {
        for ($j=0; $j<$max_cols; $j++) {
          if (!isset($csvArray[$i][$j])) {
            $csvArray[$i][$j] = '';
          }
        }
      }    
    } else {
      // error opening file
      die('ERROR OPENING FILE: '.$file);
    }
    return $csvArray;
  } // end function ReadCSV

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now