Author Topic: file() not working correctly  (Read 1667 times)

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
file() not working correctly
« on: March 21, 2011, 09:39:54 AM »
Language: PHP

So I have a small utility being used by one of my clients and they have a bunch of different CSV files that they are uploading.  The logic takes the file and reads it into an array using file().  HOWEVER, a few of the files apparently have different line break characters because it's reading the entire file as a single line.  Is there a quick way to get around this without changing the code to read in the lines looking for all possible line break characters?

If I open the file in Excel, it reads it in just fine, so it is obviously using some sort of line break character that Excel can read, but that a linux filesystem cannot.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: file() not working correctly
« Reply #1 on: March 21, 2011, 09:46:59 AM »

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: file() not working correctly
« Reply #2 on: March 21, 2011, 10:03:20 AM »
I know you got it working but... http://php.net/manual/en/function.fgetcsv.php

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: file() not working correctly
« Reply #3 on: March 21, 2011, 10:34:54 AM »
That's overkill for what I need out of this, but thanks.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: file() not working correctly
« Reply #4 on: March 21, 2011, 10:53:24 AM »
speaking of overkill, I ran across a pretty sweet class for importing xls files w/ PHP.   If anyone's interested I can try and dig it up tonight.
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: file() not working correctly
« Reply #5 on: March 21, 2011, 10:54:01 AM »
Man, that must be a nightmare to maintain