aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-05-05 14:31:53 -0300
committerSilvio <silvio@devlet.com.br>2010-05-05 14:31:53 -0300
commit858b0424c630bc1b4da42d7ab9b8fdbe05d50b62 (patch)
tree6c9b62c993bb3a13e83dfb99fbaea21963257c8a
parentac1c73e16ddd53b40af71c6783cb542bcebc6944 (diff)
downloadcinisis-858b0424c630bc1b4da42d7ab9b8fdbe05d50b62.tar.gz
cinisis-858b0424c630bc1b4da42d7ab9b8fdbe05d50b62.tar.bz2
CSV code cleanup
-rw-r--r--tests/csv.php15
1 files changed, 11 insertions, 4 deletions
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]);
}
}
}