silarhi / cfonb-parser
A PHP parser for CFONB 120 and 240 bank files (statements and transfers), with zero dependencies
Requires
- php: >=8.2
Requires (Dev)
- dg/bypass-finals: ^1.11.0
- ergebnis/composer-normalize: ^2.54.0
- friendsofphp/php-cs-fixer: ^3.95.27
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.3.1
- phpstan/phpstan-strict-rules: ^2.1.0
- phpunit/phpunit: ^11.5.57 || ^12.5.38 || ^13.4.1
- rector/rector: ^2.7.0
- rector/swiss-knife: ^2.7.0
- vimeo/psalm: ^5.26.1 || ^6.20.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
CFONB Parser
Parse French CFONB 120 and 240 bank files into typed PHP objects.
Bank statements and transfers, with zero runtime dependencies.
📖 Documentation
Features
- Zero dependencies — only PHP is required, nothing else gets pulled into your project.
- CFONB 120 statements —
Statementobjects with opening/closing balances (01/07), operations (04) and their details (05). - CFONB 240 transfers —
Transferobjects with a header (31), transactions (34) and a total (39). - Signed amounts — CFONB 120 decimals and sign characters are decoded: credits are positive, debits are negative.
- Typed value objects — getters return floats, dates (
DateTimeImmutablefor CFONB 120, typedDateTimeInterfacefor CFONB 240) and nullable strings, not raw arrays. - Tolerant input — handles
\n,\r\nand\r(since 6.5) line endings, and files with no line breaks at all. - Strict parsing — malformed lines and, since 6.5, records out of order and zero-filled dates throw a
ParseExceptioninstead of producing silent garbage, whatever the mode: non-strict mode only accepts blank CFONB 120 operation references.
Requirements
- PHP 8.2+
Installation
composer require silarhi/cfonb-parser
Quick start
use Silarhi\Cfonb\Cfonb120Reader; $reader = new Cfonb120Reader(); foreach ($reader->parse(file_get_contents('statements.txt')) as $statement) { echo sprintf("Opening balance: %.2f\n", $statement->getOldBalance()->getAmount()); foreach ($statement->getOperations() as $operation) { echo sprintf("%s %s %.2f\n", $operation->getDate()->format('Y-m-d'), $operation->getLabel(), $operation->getAmount()); } echo sprintf("Closing balance: %.2f\n", $statement->getNewBalance()->getAmount()); }
CFONB 240 transfers are read the same way with Cfonb240Reader, both formats with CfonbReader.
Documentation
Everything else is on cfonb-parser.silarhi.dev:
- Installation and quick start
- Guides: CFONB 120 statements, CFONB 240 transfers, recipes, troubleshooting
- Reference: readers, CFONB 120 objects, CFONB 240 objects, operation codes, exceptions
Contributing
See CONTRIBUTING.md.
License
MIT License. See LICENSE for details.
Built with care by SILARHI.
If CFONB Parser saves you time, consider giving it a star on GitHub.