You are here

function _find_csv_delimiter in Easychart 7.3

Helper function to find the delimiter in a csv file.

1 call to _find_csv_delimiter()
_easychart_update_csv_from_url in ./easychart.helpers.inc
Update the csv data from the url stored in the database.

File

./easychart.helpers.inc, line 95
Easychart helpers.

Code

function _find_csv_delimiter($data) {

  // possible delimiters
  $delimiters = array(
    'tab' => "\t",
    'comma' => ",",
    'semicolon' => ";",
  );

  // Count how much a possible delimiter appears.
  $delimiters_found = array();
  foreach ($delimiters as $key => $value) {
    $delimiters_found[$key] = count(explode($value, $data)) - 1;
  }

  // Get the highest appearance score.
  arsort($delimiters_found);
  reset($delimiters_found);
  $delimiter = key($delimiters_found);
  return $delimiters[$delimiter];
}