Hi, I'm reading a csv file and using it to create, insert and modify a MySQL database. I'm trying to write it in such a way as to be as bullet proof as possible and loaded with comments so I can release it to anyone else who wants to do similar.
At least one bullet is getting through

The first line of the csv file is;
- PHP: Select all
"FileLocation","FileDirectory","Filename","JFIF_APP1","Main Information","ImageDescription","Make","Model","Software","DateTime","Sub
Information","ExposureTime","FNumber","ExposureProgram","ISOSpeedRatings","ExifVersion","DateTimeOriginal","DateTimeDigitized","Brigh
tnessValue","ExposureBiasValue","MaxApertureValue","MeteringMode","LightSource","Flash","FocalLength","ImageWidth","ImageHeight","Exp
osureMode","WhiteBalance","DigitalZoomRatio","FocalLength(35mm)","SceneCaptureType","GainControl","Contrast","Saturation","Sharpness"
,"SubjectDistanceRange"
As you might imagine my database is for images. Anyway,
- PHP: Select all
$data = fgetcsv($handle, $length);
reads it all in and creates my database OK. But as I say I want to release it and make it as fail safe as possible for myself and others. If one of the first three fields has a ' or a ` in it then fgetcsv reads in the data ok. If two of the fields have those characters it fails. A vardump of $data gives...
- Code: Select all
array(4) {
[0]=>
string(13) "File`Location"
[1]=>
string(13) "FileDirectory"
[2]=>
string(9) "Fi'lename"
[3]=>
string(0) ""
}
Strangely, if the second ' or ` is later on in the fields list it all works OK

Needless to say I've looked at this all ways up and it's doing my bonce in.
Hope someone can help.
Thanks
Phillip