You are here

function webform_exporter_delimited::add_row in Webform 6.3

Same name and namespace in other branches
  1. 5.2 webform_export.inc \webform_exporter_delimited::add_row()
  2. 6.2 webform_export.inc \webform_exporter_delimited::add_row()
  3. 7.4 includes/exporters/webform_exporter_delimited.inc \webform_exporter_delimited::add_row()
  4. 7.3 includes/webform.export.inc \webform_exporter_delimited::add_row()

Overrides webform_exporter::add_row

File

includes/webform.export.inc, line 118
Provides several different handlers for exporting webform results.

Class

webform_exporter_delimited

Code

function add_row(&$file_handle, $data) {
  foreach ($data as $key => $value) {

    // Escape inner quotes and wrap all contents in new quotes.
    $data[$key] = '"' . str_replace('"', '""', $data[$key]) . '"';

    // Remove <script> tags, which mysteriously cause Excel not to import.
    $data[$key] = preg_replace('!<(/?script.*?)>!', '[$1]', $data[$key]);
  }
  $row = implode($this->delimiter, $data) . "\n";
  if (function_exists('mb_convert_encoding')) {
    $row = mb_convert_encoding($row, 'UTF-16LE', 'UTF-8');
  }
  @fwrite($file_handle, $row);
}