Skip to content

About

A PHP parser for CFONB 120 and 240 bank files (statements and transfers), with zero dependencies

Topics

Resources

Contributing

Security policy

Stars

10 stars

Watchers

3 watching

Forks

Latest commit

 

History

557 Commits

Folders and files

Repository files navigation

Latest Stable Version Total Downloads License PHP Version CI Status Coverage

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 — Statement objects with opening/closing balances (01/07), operations (04) and their details (05).
  • CFONB 240 transfers — Transfer objects 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.
  • Exact amounts — since 6.6, every amount is also an exact decimal string (getAmount(true), "-22.79"), to store and add without float errors.
  • Consistency checks — since 6.6, validate() checks that a statement's operations belong to its account and add up to its closing balance, and that a transfer's transactions add up to its total.
  • Typed value objects — getters return floats, dates (DateTimeImmutable for CFONB 120, typed DateTimeInterface for CFONB 240) and nullable strings, not raw arrays.
  • Tolerant input — handles \n, \r\n and \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 ParseException instead of producing silent garbage, whatever the mode: non-strict mode only accepts blank CFONB 120 operation references. Since 6.6, its message keeps the line (account numbers, labels) out: getRawContent() returns it.

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:

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.

About

A PHP parser for CFONB 120 and 240 bank files (statements and transfers), with zero dependencies

Topics

Resources

Contributing

Security policy

Stars

10 stars

Watchers

3 watching

Forks

Releases

Used by

Contributors

Languages