1. Go to this page and download the library: Download asgrim/ofxparser library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
asgrim / ofxparser example snippets
$ofxParser = new \OfxParser\Parser();
$ofx = $ofxParser->loadFromFile('/path/to/your/bankstatement.ofx');
$bankAccount = reset($ofx->bankAccounts);
// Get the statement start and end dates
$startDate = $bankAccount->statement->startDate;
$endDate = $bankAccount->statement->endDate;
// Get the statement transactions for the account
$transactions = $bankAccount->statement->transactions;
// You'll probably want to alias the namespace:
use OfxParser\Entities\Investment as InvEntities;
// Load the OFX file
$ofxParser = new \OfxParser\Parsers\Investment();
$ofx = $ofxParser->loadFromFile('/path/to/your/investments_file.ofx');
// Loop over investment accounts (named bankAccounts from base lib)
foreach ($ofx->bankAccounts as $accountData) {
// Loop over transactions
foreach ($accountData->statement->transactions as $ofxEntity) {
// Keep in mind... not all properties are inherited for all transaction types...
// Maybe you'll want to do something based on the transaction properties:
$nodeName = $ofxEntity->nodeName;
if ($nodeName == 'BUYSTOCK') {
// @see OfxParser\Entities\Investment\Transaction...
$amount = abs($ofxEntity->total);
$cusip = $ofxEntity->securityId;
// ...
}
// Maybe you'll want to do something based on the entity:
if ($ofxEntity instanceof InvEntities\Transaction\BuyStock) {
// ...
}
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.