You are here

function node_import_write_to_string in Node import 6

Returns one line in the specified file format of the array of values.

Parameters

$values: Array of strings.

$file_options: Array with 'record separator', 'field separator', 'text delimiter' and 'escape character'. If not set, the options default to the CSV options ("\n", ',', '"', '"').

Return value

String.

Related topics

2 calls to node_import_write_to_string()
NodeImportTestCase::nodeImportCreateFile in tests/NodeImportTestCase.php
Create a file with the specified data.
node_import_view_form_submit_download in ./node_import.admin.inc

File

./node_import.inc, line 1983
Public API of the Node import module.

Code

function node_import_write_to_string($values, $file_options) {

  // File options.
  _node_import_sanitize_file_options($file_options);
  $rs = $file_options['record separator'];
  $fs = $file_options['field separator'];
  $td = $file_options['text delimiter'];
  $ec = $file_options['escape character'];

  // Write data.
  $output = '';
  if (is_array($values) && !empty($values)) {

    // TODO: we could avoid writing $td if the $value does not contain $td, $fs or $rs.
    if (drupal_strlen($td) > 0) {
      foreach ($values as $i => $value) {
        $values[$i] = $td . str_replace($td, $ec . $td, $value) . $td;
      }
    }
    $output = implode($fs, $values);
  }
  return $output . $rs;
}