https://github.com/ixnode/php-iban
PHP IBAN - This library provides a converter for account number, bank code and IBAN.
https://github.com/ixnode/php-iban
Last synced: 11 months ago
JSON representation
PHP IBAN - This library provides a converter for account number, bank code and IBAN.
- Host: GitHub
- URL: https://github.com/ixnode/php-iban
- Owner: ixnode
- License: mit
- Created: 2023-09-01T23:08:08.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-06-04T20:15:45.000Z (about 2 years ago)
- Last Synced: 2025-07-14T05:09:34.695Z (11 months ago)
- Language: PHP
- Size: 143 KB
- Stars: 3
- Watchers: 1
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP IBAN
[](https://github.com/ixnode/php-iban/releases)
[](https://github.com/ixnode/php-iban/releases)

[](https://www.php.net/supported-versions.php)
[](https://phpstan.org/user-guide/rule-levels)
[](https://phpunit.de)
[](https://www.php-fig.org/psr/psr-12/)
[](https://github.com/phpmd/phpmd)
[](https://github.com/rectorphp/rector)
[](https://github.com/ixnode/php-api-version-bundle/blob/master/LICENSE)
> This library provides a converter for account number, bank code and IBAN.
## 1. Usage
Some usage examples.
### 1.1 IBAN parser example
```php
use Ixnode\PhpIban\Iban;
use Ixnode\PhpIban\Validator;
...
$iban = 'DE02120300000000202051';
$validator = new Validator(new Iban($iban));
print $validator->isValid() ? 'YES' : 'NO';
// (string) YES
print $validator->getAccount()->getAccountNumber();
// (string) 0000202051
print $validator->getIban()->getIbanFormatted();
// (string) DE02 1203 0000 0000 2020 51
etc.
```
### 1.2 Account number and bank code converter example (AT, CH, DE, LI, etc.)
```php
use Ixnode\PhpIban\Account;
...
$accountNumber = '0000202051';
$bankCode = '12030000';
$countryCode = 'DE';
$account = new Account($accountNumber, $bankCode, $countryCode);
print $account->getIban();
// (string) DE02120300000000202051
print $account->getIbanFormatted();
// (string) DE02 1203 0000 0000 2020 51
```
### 1.3 Account number and bank code converter example (FR)
```php
use Ixnode\PhpIban\Account;
use Ixnode\PhpIban\Constant\IbanFormats;
...
$accountNumber = '00020053701';
$bankCode = '30027';
$countryCode = 'FR';
$branchCode = '17533';
$nationalCheckDigits = '59';
$account = new Account($accountNumber, $bankCode, $countryCode, [
IbanFormat::KEY_BRANCH_CODE => $branchCode,
IbanFormat::KEY_NATIONAL_CHECK_DIGITS => $nationalCheckDigits,
]);
print $account->getIban();
// (string) FR7630027175330002005370159
print $account->getIbanFormatted();
// (string) FR76 3002 7175 3300 0200 5370 159
```
## 2. Supported countries
Checked countries and added tests (other countries might work too):
* AD (Andorra)
* AE (United Arab Emirates)
* AL (Albania)
* AT (Austria)
* AZ (Azerbaijan)
* BA (Bosnia and Herzegovina)
* BE (Belgium)
* BG (Bulgaria)
* BH (Bahrain)
* BR (Brazil)
* BY (Belarus)
* CH (Switzerland)
* CR (Costa Rica)
* CY (Cyprus)
* CZ (Czechia)
* DE (Germany)
* DK (Denmark)
* DO (Dominican Republic)
* EE (Estonia)
* EG (Egypt)
* ES (Spain)
* FI (Finland)
* FO (Faroe Islands)
* FR (France)
* GB (United Kingdom of Great Britain and Northern Ireland)
* GE (Georgia)
* GI (Gibraltar)
* GL (Greenland)
* GR (Greece)
* GT (Guatemala)
* HR (Croatia)
* HU (Hungary)
* IE (Ireland)
* IL (Israel)
* IQ (Iraq)
* IS (Iceland)
* IT (Italy)
* JO (Jordan)
* KW (Kuwait)
* KZ (Kazakhstan)
* LB (Lebanon)
* LC (Saint Lucia)
* LI (Liechtenstein)
* LT (Lithuania)
* LU (Luxembourg)
* LV (Latvia)
* MC (Monaco)
* ME (Montenegro)
* MD (Moldova)
* MK (North Macedonia)
* MR (Mauritania)
* MT (Malta)
* MU (Mauritius)
* NL (Netherlands)
* NO (Norway)
* PK (Pakistan)
* PL (Poland)
* PS (Palestine)
* PT (Portugal)
* QA (Qatar)
* RO (Romania)
* RS (Serbia)
* SA (Saudi Arabia)
* SC (Seychelles)
* SE (Sweden)
* SI (Slovenia)
* SK (Slovakia)
* SM (San Marino)
* ST (Sao Tome and Principe)
* SV (El Salvador)
* TN (Tunisia)
* TL (Timor-Leste)
* TR (Turkey)
* VG (Virgin Islands)
* UA (Ukraine)
* XK (Kosovo)
All added countries you can find here: `Ixnode\PhpIban\Constant\IbanFormats::IBAN_FORMATS`
See https://en.wikipedia.org/wiki/International_Bank_Account_Number#IBAN_formats_by_country to add more countries.
## 3. Installation
```bash
composer require ixnode/php-iban
```
```bash
vendor/bin/php-iban -V
```
```bash
0.1.0 (2023-09-01 21:09:52) - Björn Hempel
```
## 4. Command line tool
### 4.1 Check IBAN number
> Used to quickly check a given IBAN number.
```bash
bin/console iban:validate MU17BOMM0101101030300200000MUR
```
or within your composer project:
```bash
bin/console iban:validate MU17BOMM0101101030300200000MUR
```
```bash
Given IBAN: MU17BOMM0101101030300200000MUR
Parsed IBAN
-----------
Valid: YES
Last error: N/A
IBAN: MU17BOMM0101101030300200000MUR
IBAN: MU17 BOMM 0101 1010 3030 0200 000M UR
Checksum: 17
Format: MUkkbbbbbbsscccccccccccc000mmm
Parts: country-code=MU, iban-check-digits=17, national-bank-code=BOMM01, branch-code=01, account-number=101030300200, number=000, currency-code=MUR
Account
-------
Country: MU (Mauritius)
Checksum: 17
Balance cccount number: N/A
National bank code: BOMM01
Account number: 101030300200
National identification number: N/A
Currency code: MUR
Owner account number: N/A
Account number prefix: N/A
Bic bank code: N/A
Branch code: 01
Account type: N/A
National check digits: N/A
IBAN (from account): MU17BOMM0101101030300200000MUR
IBAN (from account): MU17 BOMM 0101 1010 3030 0200 000M U
```
### 4.2 Generate IBAN number
> Used to quickly generate an IBAN number.
```bash
bin/console account-number:validate 0000202051 12030000
```
or within your composer project:
```bash
vendor/bin/php-iban account-number:validate 0000202051 12030000
```
```bash
Given account number: 0000202051
Given bank code: 12030000
Given country code: DE
Parsed IBAN
-----------
IBAN: DE02120300000000202051
Valid: YES
Last error: N/A
Country: DE
Checksum: 02
Account number: 0000202051
Bank number: 12030000
```
## 5. Library development
```bash
git clone git@github.com:ixnode/php-iban.git && cd php-iban
```
```bash
composer install
```
```bash
composer test
```
## 6. License
This library is licensed under the MIT License - see the [LICENSE](/LICENSE) file for details.