Quick start
A CFONB 120 file is a list of 120 characters lines. This one holds three statements of two accounts:
0110278 02204EUR2 00012345603 060420 0000000166956E0604200704200410556677202204EUR2 00012345603B1070420 070420PRLV SEPA ONLINE SAS 0000000000000000000227R0510556677202204EUR2 00012345603B1070420 LIBDEDIBOX 37061140710278 02204EUR2 00012345603 070420 0000000166728F0110278 02204EUR2 00020427603 070420 0000000166728F0704200804200410556677202204EUR2 00020427603B1080420 080420PRLV SEPA FREE MOBILE 0000000000000000000201J0410278000202204EUR2 0002042760305080420 080420VIR JOHNDOE / FOOBAR 0000000000000000050000{0410278085902204EUR2 0002042760306080420 080420VIR BOR TEST / FOOBAR 0000000000000000000201J01/01/2025.20710278 02204EUR2 00020427603 080420 0000000216326D0110278 02204EUR2 00020427603 080420 0000000216326D0804200904200710278 02204EUR2 00020427603 090420 0000000216326DGive its contents to a Cfonb120Reader: parse() returns one Statement per opening (01) and closing (07)
balance pair, with the operations (04) between them.
<?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());}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.86Account 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.64Account 00020427603, EUR 2020-04-08 Opening balance 21632.64 2020-04-09 Closing balance 21632.64Every example of this documentation parses the files of
docs/examples/, and the outputs shown are what the
library really prints.
Both formats
Section titled “Both formats”CfonbReader reads both formats, through a Cfonb120Reader and a Cfonb240Reader:
<?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));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[] |
Next steps
Section titled “Next steps”- CFONB 120 statements: balances, operations, details and the strict mode
- CFONB 240 transfers: header, transactions and total
- Recipes: filtering, totals, arrays and JSON, several accounts
- Troubleshooting: parse errors and malformed files
