1 頁 (共 1 頁)

dbf2txt.sh

發表於 : 2018-06-01 09:33:48
yehlu

代碼: 選擇全部

#!/bin/bash
#$search_dir = '/home/backup/ntfs1/htpos/*.DBF';
for entry in "/home/backup/ntfs1/htpos"/*DBF
do
  echo "$entry"
  fname=`basename  $entry`
  echo $fname".TXT"
  php dbase01.php $entry > $fname".TXT"
done

dbase01.php

發表於 : 2018-06-01 09:34:37
yehlu

代碼: 選擇全部

<?php
$db = dbase_open($argv[1], 0);

if ($db) {
  $record_numbers = dbase_numrecords($db);
  for ($i = 1; $i <= $record_numbers; $i++) {
      $row = dbase_get_record_with_names($db, $i);
      if($i == 1){
          echo '{split=,}{fields=';
	  foreach($row as $key => $value){
              echo iconv('Big5','UTF-8',$key).',';
          }
	  echo "}\n";
      }
      if($row['deleted']==0){
      foreach($row as $key => $value){
          echo iconv('Big5','UTF-8//ignore',trim(preg_replace('/\s\s+/', ' ',$value))).",";
      }
      echo "\n";
      }
  }
}