You are here

protected function FeedsCSVParser::parseHeader in Feeds 7.2

Same name and namespace in other branches
  1. 6 plugins/FeedsCSVParser.inc \FeedsCSVParser::parseHeader()
  2. 7 plugins/FeedsCSVParser.inc \FeedsCSVParser::parseHeader()

Get first line and use it for column names, convert them to lower case. Be aware that the $parser and iterator objects can be modified in this function since they are passed in by reference.

Parameters

ParserCSV $parser:

ParserCSVIterator $iterator:

Return value

array|false An array of lower-cased column names to use as keys for the parsed items or FALSE if the document was empty.

1 call to FeedsCSVParser::parseHeader()
FeedsCSVParser::parse in plugins/FeedsCSVParser.inc
Implements FeedsParser::parse().

File

plugins/FeedsCSVParser.inc, line 68
Contains the FeedsCSVParser class.

Class

FeedsCSVParser
Parses a given file as a CSV file.

Code

protected function parseHeader(ParserCSV $parser, ParserCSVIterator $iterator) {
  try {
    $parser
      ->setLineLimit(1);
    $rows = $parser
      ->parse($iterator);
    if (!count($rows)) {
      return FALSE;
    }
    $header = array_shift($rows);
    foreach ($header as $i => $title) {
      $header[$i] = trim(drupal_strtolower($title));
    }
    return $header;
  } catch (Exception $e) {

    // Make sure that the file on the iterator gets properly closed when
    // exceptions occur during parsing.
    $iterator
      ->releaseHandler();
    throw $e;
  }
}