Skip to content

Instantly share code, notes, and snippets.

@berdyshev
Last active December 10, 2015 23:38
Show Gist options
  • Save berdyshev/4510548 to your computer and use it in GitHub Desktop.
Save berdyshev/4510548 to your computer and use it in GitHub Desktop.
Parse DTA file of fixed format (see spec here http://www.six-interbank-clearing.com/dl_tkicch_dta.pdf). This script parses only transactions 830 and 836 with 5 segments and total amount of transactions (890)
<?php
function parse_header($file) {
$header = array();
$header['requested_precissing_date'] = fread($file, 6);
$header['benef_bank_clearing_no'] = fread($file, 12);
$header['output_sequence_number'] = fread($file, 5);
$header['creation_date'] = fread($file, 6);
$header['order_bank_clearing_no'] = fread($file, 7);
$header['data_file_ident'] = fread($file, 5);
$header['entry_sequence_nubmer'] = fread($file, 5);
$header['transaction_type'] = fread($file, 3);
$header['payment_type'] = fread($file, 1);
$header['processing_flag'] = fread($file, 1);
return $header;
}
$f = fopen('public://DTAFILE.DTA', 'r');
$content = array();
while(!feof($f)) {
$output = array();
$output['SOH'] = fread($f, 2);
$output['header'] = parse_header($f);
$tt = $output['header']['transaction_type'];
$output['segments'][] = fread($f, 75);
if ($tt != 890) {
$output['segments'][] = fread($f, 128);
$output['segments'][] = fread($f, 128);
$output['segments'][] = fread($f, 128);
$output['segments'][] = fread($f, 128);
}
$content[] = $output;
}
fclose($f);
dpm($content);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment