<?php
require_once(dirname(dirname(__FILE__)) . '/php-iban.php');
date_default_timezone_set('UTC');
$data = `iconv -f utf8 -t ascii --byte-subst="<0x%x>" --unicode-subst="<U+%04X>" 'IBAN_Registry.txt'`;
if($data == '') { die("Couldn't read IBAN_Registry.txt - try downloading from the location described in the REGISTRY-URL file."); }
print "country_code|country_name|domestic_example|bban_example|bban_format_swift|bban_format_regex|bban_length|iban_example|iban_format_swift|iban_format_regex|iban_length|bban_bankid_start_offset|bban_bankid_stop_offset|bban_branchid_start_offset|bban_branchid_stop_offset|registry_edition|country_sepa\n";
$lines = preg_split('/[\r\n]+/',$data);
foreach($lines as $line) {
if($line != '' && !preg_match('/SEPA Country/',$line)) {
$bits = explode("\t",$line);
for($i=0;$i<count($bits);$i++) {
$bits[$i] = preg_replace('/^"(.*)"$/','$1',$bits[$i]);
$bits[$i] = preg_replace('/^ */','',$bits[$i]);
$bits[$i] = preg_replace('/ *$/','',$bits[$i]);
}
list($country_name,$country_code,$domestic_example,$bban,$bban_structure,$bban_length,$bban_bi_position,$bban_bi_length,$bban_bi_example,$bban_example,$iban,$iban_structure,$iban_length,$iban_electronic_example,$iban_print_example,$country_sepa,$contact_details) = $bits;
$country_code = strtoupper(substr($country_code,0,2));
$bban_structure = preg_replace('/[:;]/','',$bban_structure);
$iban_structure = preg_replace('/, .*$/','',$iban_structure);
$iban_electronic_example = preg_replace('/, .*$/','',$iban_electronic_example);
if($country_code=='MU') {
$iban_electronic_example = str_replace(' ','',$iban_electronic_example);
}
if($country_code=='CZ') {
$iban_electronic_example = preg_replace('/ \w{10,}+$/','',$iban_electronic_example);
$iban_print_example = preg_replace('/^(CZ.. .... .... .... .... ....).*$/','$1',$iban_print_example);
}
if($country_code=='FI') {
$iban_electronic_example = preg_replace('/ or .*$/','',$iban_electronic_example);