Project

General

Profile

« Previous | Next » 

Revision 1597

_archive/tapir2flatClient/trunk/client/tapir2flat.php: Upgraded to use fputcsv(). This should fix errors caused by embedded delimeters. configurableParams.php: Set default delimeter to ','.

View differences:

_archive/tapir2flatClient/trunk/client/configurableParams.php
15 15

  
16 16
# The seperator to be used in the flat file to seperate the 
17 17
# data fields of each record.
18
$seperator = '`';
18
$seperator = ',';
19 19

  
20 20
# Tapir services have an extremely flexable syntax to search for
21 21
# records with the desired properties.  However, this flexibility
_archive/tapir2flatClient/trunk/client/tapir2flat.php
2 2
#############################################################################
3 3
# Driver file for taiper2flatClient, a simple script to 
4 4
# consume taiper web services and save the results in a delimited file,
5
# one record per line.  The current delimiter is backtick '`' but
5
# one record per line.  The current delimiter is comma ',' but
6 6
# that can be changed by changing the $seperator variable located
7 7
# in configurableParams.php.
8 8
#
......
200 200
      $estimated_max_from_service = $summary->item(0)->getAttribute("totalMatched");
201 201
    }
202 202

  
203
    $flat_file = fopen($flat_filename,"a");
204

  
203 205
    $records = $xmlDoc->getElementsByTagName("record");
204 206
    $recordsStr = '';
205 207
    foreach($records as $record) {
208
      $fields = array();
206 209
      foreach(array_keys($supportedConcepts) as $key){
207 210
        $element = $record->getElementsByTagName($key);
208 211
        if($element->length > 0) {
209
          $val = $element->item(0)->nodeValue;
210
          $val = preg_replace("/$seperator/"," ",$val);
211
          $val = preg_replace("/,/"," ",$val);
212
          $val = preg_replace("/\"/"," ",$val);
213
          $recordsStr .= $val;
212
          $fields[] = $element->item(0)->nodeValue;
214 213
        }
215
        $recordsStr .= $seperator;
216 214
      }
217
      $recordsStr = substr_replace($recordsStr ,"",-1);
218
      $recordsStr .= "\n";
215
      fputcsv($flat_file,$fields,$seperator);
219 216
    }
220 217

  
221
    $flat_file = fopen($flat_filename,"a");
222 218
    fwrite($flat_file,$recordsStr);
223 219
    fclose($flat_file);
224 220

  

Also available in: Unified diff