endeken / ofx-php-parser
OFX PHP parser library
Requires
- ext-libxml: *
- ext-mbstring: *
- ext-simplexml: *
Requires (Dev)
- phpunit/phpunit: ^11.0
README
This project consists of a PHP parser for OFX (Open Financial Exchange) files, implemented using PHP 8.2. Our aim is to make the process of importing OFX files as straightforward and hassle-free as possible.
Installation
Simply require the package using Composer:
$ composer require endeken/ofx-php-parser
Usage
This project primarily revolves around the OFX
class in the Endeken\OFX
namespace. This class provides a static function parse()
which is used to parse OFX data and return the parsed information. Here is a basic usage example:
<?php require 'vendor/autoload.php'; use Endeken\OFX; try { // Load the OFX data $ofxData = file_get_contents('path_to_your_ofx_file.ofx'); // Parse the OFX data $parsedData = OFX::parse($ofxData); // $parsedData is an instance of OFXData which gives you access to all parsed data // Access the sign-on status code $statusCode = $parsedData->signOn->status->code; // Accessing bank accounts data $bankAccounts = $parsedData->bankAccounts; foreach($bankAccounts as $account) { echo 'Account ID: ' .$account->accountNumber . PHP_EOL; echo 'Bank ID: ' .$account->routingNumber . PHP_EOL; // Loop through each transaction foreach ($account->statement->transactions as $transaction) { echo 'Transaction Type: ' . $transaction->type . PHP_EOL; echo 'Date: ' . $transaction->date . PHP_EOL; echo 'Amount: ' . $transaction->amount . PHP_EOL; } } } catch (Exception $e) { echo 'An error occurred: ' . $e->getMessage(); }
Acknowledgements
This library is a standalone project, however it is heavily influenced by the work done in the asgrim/ofxparser which itself is a fork of grimfor/ofxparser. We would like to acknowledge the contributions made by the developers of these projects. Our intent was not to simply fork the project, but to build upon their work while taking the library in a slightly different direction to better serve our purposes.