0

I am trying to Import a CSV file but it fails. When I run.

 print_r(fgetcsv($file));

I get Array ( [0] => ÿþA c c N o _ 1

I think the character at the front is causing the whole csv to fail to import properly.

Can someone tell me how I can programatically remove this character and import the csv?

user1479891
  • 139
  • 1
  • 2
  • 15
  • 1
    You can skip the first character by calling `fgetc($file)`. If you need to skip more characters, try `fgets($file, 3)`. Then call `fgetcsv($file)`. Pasting the first few lines (let's say 3) of your csv may be great to understand your data and issue reading it. – Mat Jul 14 '15 at 17:10
  • 1
    This is more likely charset/encoding issue. You should figure out why it's in your CSV file, or explain a bit more about the origin and how it was processed before. – mario Jul 14 '15 at 17:14
  • @mario I agree. I thought about a BOM if the file is UTF-8. – Mat Jul 14 '15 at 17:17
  • 1
    @Mat Perhaps even one of the UTF-16 variants, since OPs example string seems spaced out (null bytes I'd guess). – mario Jul 14 '15 at 17:18
  • I have tried everything. I can open the file in notepad and then save it and it works. but native it wont work. I dont control the source so i am stuck with what I have but it is IMPOSSIBLE to import – user1479891 Jul 14 '15 at 17:19
  • It was spaced out on the php file it returned. The original looks like this - normal: AccNo_1,MtgDate,Code,Venue,Location,Pool,EventNo,Gross_Sales,Refunds,Turnover,Dividends,Profit_Loss 66096718,13/07/2015,Harness,Cobram,VIC,Win,5,695.00,0.00,695.00,"1,373.60",678.60 – user1479891 Jul 14 '15 at 17:21
  • What is the output of `str_getcsv(mb_convert_encoding(fgets($file), "UTF-8", "UTF-16"))` ? And the output of `str_getcsv(mb_convert_encoding(fgets($file), "UTF-8", "ISO-8859-15"))` ? (or any encoding you think about for the 3rd parameter) – Mat Jul 14 '15 at 17:26
  • It is the character that is screwing it up. – user1479891 Jul 14 '15 at 17:52

0 Answers0