You are here

function csv_string_to_array in Taxonomy import/export via XML 7

Same name and namespace in other branches
  1. 5.2 csv_format.inc \csv_string_to_array()
  2. 5 csv_format.inc \csv_string_to_array()
  3. 6.2 csv_format.inc \csv_string_to_array()
  4. 6 csv_format.inc \csv_string_to_array()

Given a CSV string that may or may not contain quoted values, Split it into an array of values.

2 calls to csv_string_to_array()
taxonomy_xml_csvancestry_parse in formats/csvancestry_format.inc
Scan the input CSV file and create a taxonomy structure out of it.
taxonomy_xml_csv_parse in formats/csv_format.inc
Scan the input CSV file and create a taxonomy structure out of it.

File

formats/csv_format.inc, line 224
Include routines for CSV parsing and taxonomy/term creation.

Code

function csv_string_to_array($str) {
  if (drupal_substr($str, 0, 1) == '#' || drupal_substr($str, 0, 1) == ';') {
    return;
  }
  $expr = "/,(?=(?:[^\"]*\"[^\"]*\")*(?![^\"]*\"))/";
  $results = preg_split($expr, $str);
  $results = array_map('trim', $results);
  return preg_replace("/^\"(.*)\"\$/", "\$1", $results);
}