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 Link to comment https://forums.phpfreaks.com/topic/116132-read-csv-headers/ 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); Link to comment https://forums.phpfreaks.com/topic/116132-read-csv-headers/#findComment-597194 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. Link to comment https://forums.phpfreaks.com/topic/116132-read-csv-headers/#findComment-597804 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.