Jump to content

Read CSV Headers


Hooker

Recommended Posts

Hello,

 

I'm sure this is a fairly easy problem to solve but i can't seem to find alot of information on it, is there anyway to read the column headers (and just the headers) in a CSV file? i'm writing an automised system that requires a person to identify which headers are which but the csv files are millions of rows and reading the entire file isn't practical.

 

If anyone could help me i'd really appreciate it.

 

Thanks

Link to comment
Share on other sites

If the headers are just the first, comma separated, can't you just do:

 

do { $headers = explode(',', fgets($fp = fopen('file.csv', 'r')); } while(count($headers) < 2 && !feof($fp));
fclose($fp);

function utrim(&$v){
$v=trim($v);
}

array_walk($headers, utrim);

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.