Web Design and Development Forums

fgetcsv problem with special characters

This is a discussion on "fgetcsv problem with special characters" within the PHP Forum section. This forum, and the thread "fgetcsv problem with special characters are both part of the Program Your Website category.


Go Back   Webforumz.com > Program Your Website > PHP Forum

Welcome to Webforumz.com.
Register Now Register now!

Reply
 
LinkBack Thread Tools Rate Thread
Old Apr 18th, 2008, 20:06   #1 (permalink)
Junior Member
 
Join Date: May 2007
Location: London
Posts: 11
fgetcsv problem with special characters

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
pwbiggs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old Apr 27th, 2008, 19:25   #2 (permalink)
Junior Member
 
Join Date: May 2007
Location: London
Posts: 11
Re: fgetcsv problem with special characters

No replies eh? Got you all baffled Anyway I've 'released' my csv to mysql script to anyone who needs such a thing. It still has the above 'bug' in it. Probably a lot more besides. Whether it will actually cause problems in other peoples real life data is probably not that likely, but I've warned of the problem in the notes.
If anyone wants it it's at
http://www.imagefair.co.uk/miscellaneous.html
pwbiggs is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Read First 3 characters and last 4 characters of string JustinStudios PHP Forum 2 Apr 4th, 2008 00:01
Get var not working with special characters skuliaxe PHP Forum 0 Mar 30th, 2008 22:35
A special trick pengyou New to Web Design 8 May 23rd, 2007 13:55
Cannot Submit Special Characters from Input Fields sboot ASP.NET Forum 1 Aug 30th, 2006 16:08
using special font skyfire400 HTML Forum 2 Mar 1st, 2006 00:47



Latest Updates

All Points SEO Security Advisory - CHECK YOUR SITE NOW!

Creative Coding :: February 2008

Webforumz is sponsored by: WESH UK Web Hosting
All times are GMT. The time now is 19:20.

Sleep Study Scoring :: Free Bet :: Website Templates :: Online Betting :: Bookmakers :: Funny Quotes :: Internet Recruitment Software :: Microsoft CRM Experts :: Online Casino :: Decorated Christmas Trees :: Midwife Forums :: Football Betting :: Ecommerce Software :: Web Hosting :: Football Stats :: Dry Cleaning Collection :: xtreme wales - extreme clothing :: Apuestas :: Sharepoint Consultants :: Website Optimisation :: Office Clearance London :: Sharepoint Experts :: Sports Betting :: Casino :: Website Templates :: Web Design Development India :: Online Gambling

Powered by: vBulletin Version 3.7, Copyright ©2000 - 2008, Jelsoft Enterprises Limited.
© 2003-2008 Webforumz.com : All Rights Reserved
Search Engine Friendly URLs by vBSEO 3.2.0 RC6


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59