Hooker Posted July 23, 2008 Share Posted July 23, 2008 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 Quote Link to comment Share on other sites More sharing options...
tibberous Posted July 23, 2008 Share Posted July 23, 2008 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); Quote Link to comment Share on other sites More sharing options...
Hooker Posted July 23, 2008 Author Share Posted July 23, 2008 Thanks, this is the level of thought i have at 5am with the flu. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.