Skip to content

Quick start

A CFONB 120 file is a list of 120 characters lines. This one holds three statements of two accounts:

statements.txt
0110278 02204EUR2 00012345603 060420 0000000166956E060420070420
0410556677202204EUR2 00012345603B1070420 070420PRLV SEPA ONLINE SAS 0000000000000000000227R
0510556677202204EUR2 00012345603B1070420 LIBDEDIBOX 3706114
0710278 02204EUR2 00012345603 070420 0000000166728F
0110278 02204EUR2 00020427603 070420 0000000166728F070420080420
0410556677202204EUR2 00020427603B1080420 080420PRLV SEPA FREE MOBILE 0000000000000000000201J
0410278000202204EUR2 0002042760305080420 080420VIR JOHNDOE / FOOBAR 0000000000000000050000{
0410278085902204EUR2 0002042760306080420 080420VIR BOR TEST / FOOBAR 0000000000000000000201J01/01/2025.2
0710278 02204EUR2 00020427603 080420 0000000216326D
0110278 02204EUR2 00020427603 080420 0000000216326D080420090420
0710278 02204EUR2 00020427603 090420 0000000216326D

Give its contents to a Cfonb120Reader: parse() returns one Statement per opening (01) and closing (07) balance pair, with the operations (04) between them.

quick-start.php
<?php
use Silarhi\Cfonb\Cfonb120Reader;
$reader = new Cfonb120Reader();
foreach ($reader->parse(file_get_contents('statements.txt')) as $statement) {
$opening = $statement->getOldBalance();
$closing = $statement->getNewBalance();
echo sprintf("Account %s, %s\n", $opening->getAccountNumber(), $opening->getCurrencyCode());
echo sprintf(" %s %-22s %10.2f\n", $opening->getDate()->format('Y-m-d'), 'Opening balance', $opening->getAmount());
foreach ($statement->getOperations() as $operation) {
echo sprintf(" %s %-22.22s %10.2f\n", $operation->getDate()->format('Y-m-d'), $operation->getLabel(), $operation->getAmount());
}
echo sprintf(" %s %-22s %10.2f\n", $closing->getDate()->format('Y-m-d'), 'Closing balance', $closing->getAmount());
}
Output
Account 00012345603, EUR
2020-04-06 Opening balance 16695.65
2020-04-07 PRLV SEPA ONLINE SAS -22.79
2020-04-07 Closing balance 16672.86
Account 00020427603, EUR
2020-04-07 Opening balance 16672.86
2020-04-08 PRLV SEPA FREE MOBILE -20.11
2020-04-08 VIR JOHNDOE / FOOBAR 5000.00
2020-04-08 VIR BOR TEST / FOOBAR -20.11
2020-04-08 Closing balance 21632.64
Account 00020427603, EUR
2020-04-08 Opening balance 21632.64
2020-04-09 Closing balance 21632.64

Every example of this documentation parses the files of docs/examples/, and the outputs shown are what the library really prints.

CfonbReader reads both formats, through a Cfonb120Reader and a Cfonb240Reader:

cfonb-reader.php
<?php
use Silarhi\Cfonb\CfonbReader;
$reader = new CfonbReader();
$statements = $reader->parseCfonb120(file_get_contents('statements.txt'));
$transfers = $reader->parseCfonb240(file_get_contents('transfers.txt'));
echo sprintf("%d statements, %d transfers\n", count($statements), count($transfers));
Output
3 statements, 2 transfers
Method Same as
parseCfonb120(string $content, bool $strict = true): array Cfonb120Reader::parse(), Statement[]
parseCfonb240(string $content, bool $strict = true): array Cfonb240Reader::parse(), Transfer[]