I’m having a few problems exploding data in a .csv file to read into a database.
This is the structure of the .csv file:
Stock ID,VRM,Manufacturer,Model,Trim,Door,Body,Colour,Transmission Speed,Transmission Type,Fuel Type,Engine Size,Year of manufacture,Reg letter/number,No. of keepers,Price,VAT qualifying indicator,Mileage,1st registration date,Vehicle description,Narrative,Standard Options,Additional Options,Image 1 url,Image 2 url,Image 3 url,Image 4 url,Image 5 url,Image 6 url,Image 7 url,Image 8 url,Image 9 url,Image 10 url,Image 11 url,Image 12 url
18109357,TEST,Suzuki,Alto,SZ4,5 Door,Hatchback,Grey,4 speed,Automatic,Petrol,996,2013,13,1,7495,N,3412,25/06/2013,Suzuki Alto 1.0 SZ4 5 Door Hatchback,“ABS(Anti-Lock Brakes),Adjustable Steering Column,Air Conditioning,Alloy Wheels,Body Coloured Bumpers,Cloth Interior,Cup Holder,Driver’s Air Bag,Electric Windows,Electronic Brake Force Distribution,Electronic Stability Programme,Front Fog Lights,High Level Brake Light,Immobiliser,Mirrors External,Passenger Air Bag,Power-Assisted Steering,Seat - ISOFIX Anchorage Point,Seat Belt Pre-Tensioners,Seat Height Adjustment”,“Speakers,Split-Folding Rear Seats,Tinted Glass”,images/1600/1200/70/0/DOW/18/109/18109357_0_0.3165532943823276_ORIG.jpg,images.com/1600/1200/70/0/DOW/18/109/18109357_1_0.3090620155890714_ORIG.jpg,images.com/1600/1200/70/0/DOW/18/109/18109357_2_0.46076542172304336_ORIG.jpg,images.com/1600/1200/70/0/DOW/18/109/18109357_3_0.2732333010929473_ORIG.jpg,images.com/1600/1200/70/0/DOW/18/109/18109357_4_0.6469716347737734_ORIG.jpg,,,,,,,
The php code I have to explode the data works to a point.
It recognises the first set of " marks in the file but the problem is when it gets to the second set it doesn;t import correctly.
This is the explode statement in the code:
$data = fgets($fh);
list($data1,$data2) = explode('"',$data,2);
$data2 = str_replace(array("'", '*', '£', 'é'),array('#', '', '£', 'é'),$data2);
$data = explode(',',$data1.$data2);
Can anyone help with this please?