From 858b0424c630bc1b4da42d7ab9b8fdbe05d50b62 Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 5 May 2010 14:31:53 -0300 Subject: CSV code cleanup --- tests/csv.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/csv.php b/tests/csv.php index 6c06322..2787575 100644 --- a/tests/csv.php +++ b/tests/csv.php @@ -3,6 +3,13 @@ * Cinisis - Isis db reading tool. */ +/** + * Format a value for CSV output. + */ +function csv($field) { + return '"'. preg_replace('/"/', '""', $field) .'",'; +} + // Import Cinisis Library. require_once '../index.php'; @@ -23,10 +30,10 @@ if ($isis->db) { // Format fields. foreach ($format['fields'] as $field) { - echo $field['name'] .','; + echo csv($field['name']); if (is_array($field['subfields'])) { foreach ($field['subfields'] as $key => $value) { - echo $field['name'] .': '. $value.','; + echo csv($field['name'] .': '. $value); } } } @@ -35,10 +42,10 @@ if ($isis->db) { for ($n=1; $n <= $rows; $n++) { $result = $isis->db->read($n); foreach ($format['fields'] as $field) { - echo $result[$field['name']] .','; + echo csv($result[$field['name']]); if (is_array($field['subfields'])) { foreach ($field['subfields'] as $key => $value) { - echo $result[$field['name']][$value] .','; + echo csv($result[$field['name']][$value]); } } } -- cgit v1.2.3