If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

fgetcsv OR SplFileObject HELP!!

Hi guys.

I have a CSV file that I am trying to import to a mysql database.

The issue i am having is that the system we export the CSV files from seems to enclose SOME 'columns' with a " character. I am assuming it does this when the column contains a , character (for example in a name like DOE, JANE) that I dont want to be split into a separate column.

I can't seem to work out the correct code to make this happen. Here is an example of a line.

No, you don't want to do that. The " are designed as enclosures (although the third parameter isn't necessary at all) and exist only when wrapping data that includes the ,. If you do that it will only seek to separate on "," instead of ignoring , which is surrounded by ".
Unless the user is looking for 13 results based completely on the ,? If that's the case, than an explode of the whole line would be easier.

Edit:
Actually, according to the doc you cannot do that anyways. The delimiter is only a char, not a string.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

Which I got by using unicode. So looks like the output software is saving in non-BOM unicode and not in ansi.
You should be able to issue a setlocale(LC_ALL, 'en_US.utf8');, which should use a utf8 charset. fgetcsv lists that it is locale aware.

PHP Code:

header('HTTP/1.1 420 Enhance Your Calm');

Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)