Hello friends,
In my php4dbf library, I do it exactly the same way.
But I see, despite my efforts to integrate as many functions as possible into the php4dbf library,
I am still far from the source code elegance of Harbour.
Best regards,
Otto
In my php4dbf library, I do it exactly the same way.
But I see, despite my efforts to integrate as many functions as possible into the php4dbf library,
I am still far from the source code elegance of Harbour.
Best regards,
Otto
<?php
function parseRecord($record, $fields, $filterFields = []) {
  $result = [];
  $offset = 1;
  foreach ($fields as $field) {
   Â
    $value = rtrim(substr($record, $offset, $field['length']));
   Â
    if (empty($filterFields) || in_array($field['name'], $filterFields)) {
      if ($field['type'] === 'N') {
        $value = is_numeric($value) ? floatval($value) : 0.0;
      } elseif ($field['type'] === 'C') {
        $value = my_utf8_encode($value);
      }
      $result[$field['name']] = $value;
    }
    $offset += $field['length'];
  }
  return $result;
}
function read_dbf( $file_path) {
 Â
  $dbData = php4dbf_openFile( $file_path, true, [ 'LAST' ] );
 Â
  $records = [];
  $parsedRecords = []; Â
  for ($i = 1; $i <= php4dbf_eof( $dbData ); $i++) {  Â
    $record = php4dbf_readRecordByIndex( $dbData, $i - 1 );
    if ($record !== null) {
      $parsedRecord = parseRecord( $record, $dbData['fields'], $dbData['filterFields']);
      $parsedRecords[] = $parsedRecord;
    }
  }
  php4dbf_closeDbfFile($dbData);
  return $parsedRecords; Â
}
$file_path = "........";
$records = read_dbf($file_path);
?>