globalcitizen / php-iban

Generate, parse, validate, error-correct and present IBAN (and IIBAN) bank account information in PHP.
GNU Lesser General Public License v3.0
475 stars 110 forks source link
checksums ecbs iana iban iso iso3166 mistranscription php php-library sepa

php-iban

php-iban is a library for parsing, validating and generating IBAN (and IIBAN) bank account information in PHP.

Latest Stable Version License

All parts of an IBAN can be retrieved, including country code, checksum, BBAN, financial institution or bank code, account number, and where a fixed-length national system is in use, also branch/sort code. Legacy national checksums may also be retrieved, validated and correctly set, where available, whether they apply to the account number portion, bank and branch identifiers, part or all of the above. IBAN country codes can be converted in to ISO3166-1 alpha-2 and IANA formats, the parent IBAN country acting as registrar for dependent territories may be queried, the official national currency (ISO4217 alpha code format), central bank name and central bank URL may also be queried to ease integration. IBANs may be converted between human and machine representation. IBANs may be obfuscated for presentation to humans in special circumstances such as relative identification. A database of example/test IBANs from different countries is included. Finally, highly accurate suggestions for originally intended input can be made when an incorrect IBAN is detected and is due to mistranscription error.

The parser was built using regular expressions to adapt the contents of the official IBAN registry available from SWIFT then manually modified for special cases such as errors and omissions in SWIFT's official specifications.

Various deficiencies in the initial adaptation have since been rectified, and the current version should be a fairly correct and reliable implementation.

Where appropriate, European Committee for Banking Standards (ECBS) recommendations have also been incorporated.

Please bear in mind that because the specification changes frequently, it may not be 100% up to date if a new version has been recently released - I do my best though. We are currently thought to be up to date with the January 2020 release, ie. PDF release #86.

Licensed under LGPL, it is free to use in commercial settings.

Countries Supported

The following 116 official and unofficial IBAN countries are supported.

Installation via composer

If you use composer you can simply run composer require globalcitizen/php-iban to get going. Reportedly Daily Downloads (and Monthly Downloads) were done via composer.

(If you don't yet have composer and wish to install it in an insecure fashion (not recommended, but convenient) you can run curl -sS https://getcomposer.org/installer | php or wget -O- https://getcomposer.org/installer | php)

Then just add the following to your composer.json file:

// composer.json
{
    "require": {
        "globalcitizen/php-iban": "4.2.3"
    }
}

Then, you can install the new dependencies by running composer's update command from the directory where your composer.json file is located:

# install
$ php composer.phar install
# update
$ php composer.phar update globalcitizen/php-iban

# or you can simply execute composer command if you set it to
# your PATH environment variable
$ composer install
$ composer update globalcitizen/php-iban

You can see this library on Packagist.

Installation via git

For a regular install, use the git clone command:

# HTTP
$ git clone https://github.com/globalcitizen/php-iban.git
# SSH
$ git clone git@github.com:globalcitizen/php-iban.git

Installation via git submodule

Alternatively, to embed the php-iban library in your own git-managed repository at a specific revision number, such that it is possible to update the version in a predictable way while maintaining a larger system that depends upon its functionality:

# enter your project's git repo
$ cd my-existing-project-with-a-git-repo/
# select an appropriate place to create the php-iban subdir
$ cd lib/
# add php-iban as a submodule
$ git submodule add https://github.com/globalcitizen/php-iban.git
# commit new submodule
$ git commit -m 'Add php-iban submodule'

Then, when checking out git projects with submodules for the first time, normally you need to make a couple of extra steps:

# check out your project as normal
$ git clone git@your-server.com:your/project.git
# initialize submodules
$ git submodule init
# update submodules
$ git submodule update

To skip these steps, add the --recursive argument to git clone when checking out:

# check out your project, initialize and update all submodules
$ git clone --recursive git@your-server.com:your/project.git

If you later wish to your project to use a newer version of php-iban, run:

# fetch changes
$ git submodule update --remote php-iban
# commit
$ git commit -m 'Update php-iban submodule'

Manual installation

  1. Fetch the latest release from our github releases page in either zip or tar.gz format.
  2. Extract the library using your favourite archive utility, for example unzip filename.zip on Unix-like platforms.
  3. Write your code to depend on the library based upon its relative location to your source code. For example if you wish to include php-iban from the parent directory's subdirectory libraries/php-iban you could use the following require_once() statement:
    <?php
    require_once(dirname(__FILE__) . '/../libraries/php-iban/php-iban.php');
    # ... your code utilizing php-iban
    ?>

Comparison of PHP IBAN libraries

The following table compares php-iban to other PHP projects offering IBAN-related functionality, on the basis of general project information and the programming paradigms supported.

Project Lic. Proc OO Began Latest Star Watch Fork Installs Home culture Deps
php-iban LGPL 2009 4.2.3 426 29 104 ~7M+* Global* none
Iban MIT 2013 1.3.0 50 9 19 178.39k German lots
IsoCodes GPL3 2012 2.1.1 466 22 54 145k French lots
SepaUtil's GPL3 2014 1.2.3 8 4 3 25k German phpunit
Symfony MIT 2013 3.3.6 15k 1214 5.6k 23M+ French lots

Notes:

Now let's take a look at features.

+ ISO IANA SEPA UO MT NC CB H? Registry
php-iban 116: full, error-corrected CSV with open-source toolchain and documentation
Iban ✔* 54: partial, hardcoded, dubious origin
IsoCodes 66: partial, hardcoded, dubious origin
SepaUtil's 89: partial, hardcoded, dubious origin
Symfony 95: partial, hardcoded, dubious origin

Note:

In short, while composer users have apparently lept on rival libraries (particularly Iban), probably due to the time it took us to integrate a composer file, those libraries are often either full-fledged web frameworks or burdensome in dependencies, less mature, fail to hat-tip to the free software foundation, do not support the procedural programming paradigm (for when AbstractProductClassMakerFactories just won't cut it), use data from dubious sources, tend to use licenses that are incompatible with certain commercial uses, and are frankly short on features.

So, fearless user ... choose php-iban: the ethical, functional, forward-looking, low-hassle library of choice for IBAN and IIBAN processing. Choose to win! ;)

Your Help Wanted

News: March 2024

Version 4.2.3 has been released.

Version 4.2.2 has been released.

News: August 2023

News: January 2023

Version 4.2.1 has been released.

Version 4.2.0 has been released.

News: August 2022

Version 4.1.1 has been released.

News: July 2021

Version 4.1.0 has been released.

News: August 2020

Version 4.0.0 has been released.

Version 3.0.3 has been released.

Version 3.0.2 has been released.

News: July 2020

Version 3.0.0 has been released.

Version 2.8.2 has been released.

Version 2.8.1 has been released.

News: June 2020

Version 2.8.0 has been released.

News: May 2020

Version 2.7.5 has been released.

Version 2.7.4 has been released.

News: November 2019

Version 2.7.3 has been released.

Version 2.7.2 has been released.

News: October 2019

Version 2.7.1 has been released.

News: July 2019

Version 2.7.0 has been released.

News: August 2018

Version 2.6.9 has been released.

Version 2.6.8 has been released.

News: June 2018

Version 2.6.7 has been released.

News: June 2018

Version 2.6.6 has been released.

News: March 2018

Version 2.6.5 has been released.

Version 2.6.4 has been released.

Version 2.6.3 has been released.

Version 2.6.2 has been released.

News: August 2017

Version 2.6.1 has been released.

Version 2.6.0 has been released.

News: October 2016

Version 2.5.9 has been released.

News: August 2016

Version 2.5.8 has been released.

News: June 2016

Version 2.5.7 has been released.

News: May 2016

Version 2.5.6 has been released.

News: April 2016

Version 2.5.5 has been released.

News: March 2016

Version 2.5.4 has been released.

Version 2.5.3 has been released.

News: February 2016

Version 2.5.2 has been released.

Version 2.5.1 has been released.

Version 2.5.0 has been released.

Version 2.4.20 has been released.

Version 2.4.19 has been released.

Version 2.4.18 has been released.

Version 2.4.17 has been released.

Version 2.4.16 has been released.

Version 2.4.15 has been released.

Version 2.4.14 has been released.

Version 2.4.13 has been released.

Version 2.4.12 has been released.

Version 2.4.11 has been released.

Version 2.4.10 has been released.

Version 2.4.9 has been released.

Version 2.4.8 has been released.

Version 2.4.7 has been released.

Version 2.4.6 has been released.

Version 2.4.5 has been released.

Version 2.4.4 has been released.

Version 2.4.3 has been released.

Version 2.4.2 has been released.

Version 2.4.1 has been released.

Version 2.4.0 has been released.

News: January 2016

Version 2.3.1 has been released.

Version 2.3.0 has been released.

Version 2.2.0 has been released.

Version 2.1.9 has been released.

Version 2.1.8 has been released.

Version 2.1.7 has been released.

Version 2.1.6 has been released.

Version 2.1.5 has been released.

Version 2.1.4 has been released.

Version 2.1.3 has been released.

Version 2.1.2 has been released. All known unofficial IBAN country codes are now integrated. As well as minor documentation updates and a shortening of the reported name of Kosovo, this version adds:

Version 2.1.1 has been released. Currently unofficial IBAN country codes are being integrated, and the process remains ongoing. This version adds:

Version 2.1.0 has been released.
Currently unofficial IBAN country codes are being integrated, and the process remains ongoing. A new flag has been created to check whether a country is an official, SWIFT-issued record or not. The following new countries have therefore been added.

Note also that the IIBAN (AA) record has been marked unofficial, and features listed in docs/TODO have been migrated to Github issues and that file deleted.

Version 2.0.1 has been released. This is to celebrate real testing, composer support, as well as finally catching up with changes. This version should be up to date with all registry changes to the present, including changes or additions to the countries:

Version 1.6.0 has been released. This version features more registry corrections (newly added territories with faulty data, bad checksums in sample IBANs, etc.) as well as enhanced testing routines, extended documentation, and corrected documentation. All users are advised to upgrade. We now have automated test script execution with Travis CI, to provide additional robustness for all committed code. This took longer than expected as unfortunately I picked the exact time Travis broke their build logs - https://www.traviscistatus.com/incidents/fcllblkclgmb - to see what all the fuss was about... proving again that cloud computing is just great for breaking things unexpectedly. Because they want to hide things, there was literally no debug output whatsoever, and I was led to believe this was my fault. Fellow programmers, behold: it is the dawning of the age of the mystical fail.

Version 1.5.0 has been released. There are no code changes, but we now have http://packagist.org/ integration, hopefully this triggers it to start working. If you use packagist, you can now add the library to your project by just running composer require globalcitizen/php-iban (thanks to @acoulton for pointing the way)

Version 1.4.9 has been released using the new Github-based release process. Hopefully this provides a solid anchor point for those bundling the library with other software. We also have a contributed composer metadata file to ease integration. New IBAN registry URLs integrated. Removed old SVN tag/trunk structure.

News: July 2015

Corrected SWIFT URL to IBAN page. Emphasized mistranscription error support.

News: March 2015

Finally, google has killed code.google.com and we have migrated to Github! Once the old trunk/tag structure (lingering from svn) is cleaned up and this document translated from the old wiki format to markdown, a new version will be issued.

News: June 2014

Version 1.4.6 has been released:

Unfortunately, Google now requires code.google.com projects to use Google Drive. I tried to use Google Drive (sign up for a new account, jump through email hoops, get treated as a robot, learn stupid new touchy-feely-friendly interface, get meaningless error messages like 'Your sharing limit has been exceeded' (with 2x290KB files on a new account I was told to create) and lost patience entirely.

So for the moment, you'll just have to download using git, instead. I will migrate php-iban to Github shortly. Google really is a pain in the ass recently, what with all of this Google+ and Google Drive junk, ruining Picasa, ruining Sketchup by lack of attention, etc. What are they thinking?

News: March 2014

Version 1.4.5 has been released:

Version 1.4.4 has been released:

The project source code repository has switched from svn (ugh) to git (yay!).

News: September 2013

Version 1.4.3 has been released:

News: August 2013

Version 1.4.2 has been released:

Version 1.4.1 has been released:

News: June 2013

Version 1.4.1 is still being prepared, squashing some bugs and updating the registry ... meanwhile, it has come to my attention that we have been featured in the Code Candy blog! http://www.codecandies.com/2012/05/30/no-exceptions/ Hooray for the German sense of humour! Hahah.

News: March 2013

Version 1.4.0 has been released:

News: February 2013

Version 1.3.9 has been released:

Version 1.3.8 has been released:

Version 1.3.7 has been released:

News: November 2012

Version 1.3.6 has been released:

News: October 2012

Version 1.3.5 has been released:

Version 1.3.4 has been released:

Version 1.3.3 has been released:

News: September 2012

Version 1.3.2 has been released:

News: June 2012

Version 1.3.1 has been released:

News: December 2011

Version 1.3.0 has been released. This release adds mistranscription error suggestion support.

Version 1.2.0 has been released. This release adds Internet International Bank Account Number (IIBAN) support, as per the current IIBAN Internet Draft at http://tools.ietf.org/html/draft-iiban-01

News: September 2011

Version 1.1.2 has been released. This adds long open tags to the main library file in order to simplify deployment on many default PHP installations.

News: August 2011

Version 1.1.1 has been released. This fixes a typo in a function call in the new OO wrapper. Non OO users do not need to upgrade.

News: July 2011

Version 1.1.0 has been released. This version adds an object oriented wrapper library and related updates to documentation and test scripts. It is not critical for existing users to upgrade.

Version 1.0.0 has been released. This version includes the following changes:


Earlier in the month... Small maintenance release, not critical.

News: June 2011

News: December 2009

*We now have a http://groups.google.com/group/php-iban-users mailing list. Feel free to post your feedback, queries or suggestions - we'd love to know how you are using the library. To date, the project has reached over 400 downloads and still going strong, with more than one new user per day - a pretty good showing for a specialised library!

*version 12 has been released. The registry file has been improved, partly as a result of user reports and partly as a result of issues uncovered while performing automated tests against version 11.

Documentation (Procedural/Recommended)

require_once('php-iban.php');
# ... your code utilising IBAN functions...

Validation Functions

# Verify an IBAN number.
#  An optional second argument specifies $machine_format_only (default is false)
#  If true, the function will not tolerate unclean inputs
#   (eg. spaces, dashes, leading 'IBAN ' or 'IIBAN ', lower case)
#  If false (default), input can be in either:
#   - printed ('IIBAN xx xx xx...' or 'IBAN xx xx xx...'); or 
#   - machine ('xxxxx')
#  ... string formats.
#  Returns true or false.
if(!verify_iban($iban,$machine_format_only=false)) {
 # ...
}

# Check the checksum of an IBAN - code modified from Validate_Finance PEAR class
if(!iban_verify_checksum($iban)) {
 # ...
}

# Suggest what the user really meant in the case of transcription errors
$suggestions = iban_mistranscription_suggestions($bad_iban);
if(count($suggestions) == 1) {
 print "You really meant " . $suggestions[0] . ", right?\n";
}

# Find the correct checksum for an IBAN
$correct_checksum = iban_find_checksum($iban);

# Set the correct checksum for an IBAN
$fixed_iban = iban_set_checksum($iban);

# Verify the pre-IBAN era, BBAN-level national checksum for those countries that
# have such a system and we have implemented.
# (Returns '' if unimplemented, true or false)
$result = iban_verify_nationalchecksum($iban);
if($result == '') {
 print "National checksum system does not exist or remains unimplemented for the country of IBAN '$iban'.\n";
}
elseif($result == true) {
 print "IBAN '$iban' passes the national checksum algorithm for its country.\n";
}
else {
 print "IBAN '$iban' FAILS the national checksum algorithm for its country.\n";
}

# Set the pre-IBAN era, BBAN-level national checksum for those countries that
# have such a system, where that system results in a dedicated checksum
# substring, and that we have implemented.
# (Returns '' if unimplemented, or the corrected string)
# (NOTE: On success, the function also subsequently recalculates the IBAN-level checksum)
$national_checksum_algorithm_valid_iban = iban_set_nationalchecksum($iban);

# Determine, but do not set, the pre-IBAN era, BBAN-level national checksum 
# for those countries that have such a system, where that system results in
# a dedicated checksum substring, and that we have implemented.
# (Returns '' if unimplemented, or the expected national checksum substring)
$expected_national_checksum = iban_find_nationalchecksum($iban);

Utility Functions

# Convert an IBAN to machine format.  To do this, we
# remove IBAN from the start, if present, and remove
# non basic roman letter / digit characters
$machine_iban = iban_to_machine_format($iban);

# Convert an IBAN to human format.  To do this, we
# add a space every four characters.
$human_iban = iban_to_human_format($iban);

# Convert an IBAN to obfuscated format for relative
# identification. To do this, we replace all but the
# leading country code and final four characters with
# asterisks.
$obfuscated_iban = iban_to_obfuscated_format($iban);

IBAN Country-Level Functions

# Get the name of an IBAN country
$country_name = iban_country_get_country_name($iban_country);

# Get the domestic example for an IBAN country
$country_domestic_example = iban_country_get_domestic_example($iban_country);

# Get the BBAN example for an IBAN country
$country_bban_example = iban_country_get_bban_example($iban_country);

# Get the BBAN format (in SWIFT format) for an IBAN country
$country_bban_format_as_swift = iban_country_get_bban_format_swift($iban_country);

# Get the BBAN format (as a regular expression) for an IBAN country
$country_bban_format_as_regex = iban_country_get_bban_format_regex($iban_country);

# Get the BBAN length for an IBAN country
$country_bban_length = iban_country_get_bban_length($iban_country);

# Get the IBAN example for an IBAN country
$country_iban_example = iban_country_get_iban_example($iban_country);

# Get the IBAN length for an IBAN country
$country_iban_length = iban_country_get_iban_length($iban_country);

# Get the IBAN format (in SWIFT format) for an IBAN country
$country_iban_format_as_swift = iban_country_get_iban_format_swift ($iban_country);

# Get the IBAN format (as a regular expression) for an IBAN country
$country_iban_format_as_regex = iban_country_get_iban_format_regex($iban_country);

# Determine whether an IBAN country is a member of SEPA (Single Euro Payments Area)
if(!iban_country_is_sepa($iban_country)) {
 # ... do something xenophobic ...
}

# Get the bank ID start offset for an IBAN country
$country_bankid_start_offset = iban_country_get_bankid_start_offset($iban_country);

# Get the bank ID stop offset for an IBAN country
$country_bankid_stop_offset = iban_country_get_bankid_stop_offset($iban_country);

# Get the branch ID start offset for an IBAN country
$country_branchid_start_offset = iban_country_get_branchid_start_offset($iban_country);

# Get the branch ID stop offset for an IBAN country
$country_branchid_stop_offset = iban_country_get_branchid_stop_offset($iban_country);

# Get the registry edition for an IBAN country (note: IIBAN country 'AA' returns 'N/A')
$country_registry_edition = iban_country_get_registry_edition($iban_country);

# Determine whether an IBAN country is an official, SWIFT issued country record
if(!iban_country_get_country_swift_official($iban_country)) {
 # ... do something against decentralization ...
}

# Get the IANA code for an IBAN country
$country_iana = iban_country_get_iana($iban_country);

# Get the ISO3166-1 alpha-2 code for an IBAN country
$country_iso3166 = iban_country_get_iso3166($iban_country);

# Get the parent registrar IBAN country of an IBAN country
# (Returns '' in the normal case that the country is independently registered)
$registrar_country = iban_country_get_parent_registrar($iban_country);
if($registrar_country=='') {
 print "The mighty nation of '$iban_country' stands strong and proud...\n";
 print " ... with its own heirarchy of bureaucrats!\n";
}
else {
 print "It has been foretold that the downtrodden natives of '$iban_country' will one day\n";
 print "rise up and throw off the shackles of the evil '$registrar_country' oppressors!\n";
}

# Get the official currency of an IBAN country as an ISO4217 alpha code
# (Returns '' in the Internet (IIBAN) case, ie. no official currency)
$official_currency = iban_country_get_currency_iso4217($iban_country);
if($official_currency == '') {
 print "There is no official currency for the IBAN country '$iban_country'.\n";
}

# Get the URL of an IBAN country's central bank
# (Note: Returns '' if there is no central bank. Also, note that
#        sometimes multiple countries share one central bank)
$central_bank_url = iban_country_get_central_bank_url($iban_country);

# Get the name of an IBAN country's central bank
# (Note: Returns '' if there is no central bank. Also, note that
#        sometimes multiple countries share one central bank)
$central_bank_name = iban_country_get_central_bank_name($iban_country);

# Get the membership type of the country
# There are four types of memberships:
# * EU-Member States (eu_member)
# * EFTA-Member States (efta_member)
# * Other Memberships, which have monetary agreements with the EU (other_member)
# * Non-Members, which don't belong to the EU or have agreements (non_member)
$country_membership = iban_country_get_membership($iban_country);

# Get if the country is a eu member state
# (Note: Returns true, if member state; false otherwise)
$country_membership = iban_country_get_is_eu_member($iban_country);

Parsing Functions

# Get an array of all the parts from an IBAN
$iban_parts = iban_get_parts($iban);

# Get the country part from an IBAN
$iban_country = iban_get_country_part($iban);

# Get the BBAN part from an IBAN
$bban = iban_get_bban_part($iban);

# Get the Bank ID (institution code) from an IBAN
$bank = iban_get_bank_part($iban);

# Get the Branch ID (sort code) from an IBAN
#  (NOTE: only available for some countries)
$sortcode = iban_get_branch_part($iban);

# Get the (branch-local) account ID from an IBAN
#  (NOTE: only available for some countries)
$account = iban_get_account_part($iban);

# Get the checksum part from an IBAN
$checksum = iban_get_checksum_part($iban);

# Get the national checksum part from an IBAN (if it exists)
$checksum = iban_get_nationalchecksum_part($iban);

Documentation (Object Oriented Wrapper/Discouraged)

OO use is discouraged as there is a present-day trend to overuse the model. However, if you prefer OO PHP then by all means use the object oriented wrapper, described below.

require_once('oophp-iban.php');
# ... your code utilising object oriented PHP IBAN functions...

Validation Functions

# Example instantiation
$iban = 'AZ12345678901234'
$myIban = new IBAN($iban);

# Verify an IBAN number.
#  Tolerates spaces, prefixes "IBAN ...", dashes, lowercase input, etc.
#  Returns true or false.
if(!$myIban->Verify()) {
 # ...
}
# Verify an IBAN number in machine format only.
#  Does not tolerate lowercase input, separators, whitespace or prefixes.
#  Returns true or false.
if(!$myIban->VerifyMachineFormatOnly()) {
 # ...
}

# Check the checksum of an IBAN - code modified from Validate_Finance PEAR class
if(!$myIban->VerifyChecksum()) {
 # ...
}

# Suggest what the user really meant in the case of mistranscription errors
$suggestions = $badIban->MistranscriptionSuggestions();
if(count($suggestions)==1) {
 print "You really meant " . $suggestions[0] . ", right?\n";
}

# Find the correct checksum for an IBAN
$correct_checksum = $myIban->FindChecksum();

# Set the correct checksum for an IBAN
$fixed_iban = $myIban->SetChecksum()

# Verify the pre-IBAN era, BBAN-level national checksum for those countries that
# have such a system and we have implemented.
# (Returns '' if unimplemented, true or false)
$result = $myIban->VerifyNationalChecksum();
if($result == '') {
 print "National checksum system does not exist or remains unimplemented for this IBAN's country.\n";
}
elseif($result == true) {
 print "IBAN passes the national checksum algorithm for its country.\n";
}
else {
 print "IBAN FAILS the national checksum algorithm for its country.\n";
}

# Set the pre-IBAN era, BBAN-level national checksum for those countries that
# have such a system, where that system results in a dedicated checksum
# substring, and that we have implemented.
# (Returns '' if unimplemented, or the corrected string)
# (NOTE: On success, the function also subsequently recalculates the IBAN-level checksum)
$myIban->SetNationalChecksum();

# Determine, but do not set, the pre-IBAN era, BBAN-level national checksum
# for those countries that have such a system, where that system results in
# a dedicated checksum substring, and that we have implemented.
# (Returns '' if unimplemented, or the expected national checksum substring)
$national_checksum = $myIban->FindNationalChecksum();

Utility Functions

# Convert an IBAN to machine format.  To do this, we
# remove IBAN from the start, if present, and remove
# non basic roman letter / digit characters
$machine_iban = $myIban->MachineFormat();

# Convert an IBAN to human format.  To do this, we
# add a space every four characters.
$human_iban = $myIban->HumanFormat();

# Convert an IBAN to obfuscated format for relative
# identification. To do this, we replace all but the
# leading country code and final four characters with
# asterisks.
$obfsucated_iban = $myIban->ObfuscatedFormat();

IBAN Country-Level Functions

# To list countries, use the IBAN Class...
$myIban->Countries();

# ... everything else is in the IBANCountry class.

# Example instantiation
$countrycode = 'DE';
$myCountry = new IBANCountry($countrycode);

# Get the country code of an IBAN country
$country_code = $myCountry->Code();

# Get the name of an IBAN country
$country_name = $myCountry->Name();

# Get the domestic example for an IBAN country
$country_domestic_example = $myCountry->DomesticExample();

# Get the BBAN example for an IBAN country
$country_bban_example = $myCountry->BBANExample();

# Get the BBAN format (in SWIFT format) for an IBAN country
$country_bban_format_as_swift = $myCountry->BBANFormatSWIFT();

# Get the BBAN format (as a regular expression) for an IBAN country
$country_bban_format_as_regex = $myCountry->BBANFormatRegex();

# Get the BBAN length for an IBAN country
$country_bban_length = $myCountry->BBANLength();

# Get the IBAN example for an IBAN country
$country_iban_example = $myCountry->IBANExample();

# Get the IBAN length for an IBAN country
$country_iban_length = $myCountry->IBANLength();

# Get the IBAN format (in SWIFT format) for an IBAN country
$country_iban_format_as_swift = $myCountry->IBANFormatSWIFT();

# Get the IBAN format (as a regular expression) for an IBAN country
$country_iban_format_as_regex = $myCountry->IBANFormatRegex();

# Determine whether an IBAN country is a member of SEPA (Single Euro Payments Area)
if(!$myCountry->IsSEPA()) {
 # ... do something xenophobic ...
}

# Get the bank ID start offset for an IBAN country
$country_bankid_start_offset = $myCountry->BankIDStartOffset();

# Get the bank ID stop offset for an IBAN country
$country_bankid_stop_offset = $myCountry->BankIDStopOffset();

# Get the branch ID start offset for an IBAN country
$country_branchid_start_offset = $myCountry->BranchIDStartOffset();

# Get the branch ID stop offset for an IBAN country
$country_branchid_stop_offset = $myCountry->BranchIDStopOffset();

# Get the national checksum start offset for an IBAN country
$country_nationalchecksum_start_offset = $myCountry->NationalChecksumStartOffset();

# Get the national checksum stop offset for an IBAN country
$country_nationalchecksum_stop_offset = $myCountry->NationalChecksumStopOffset();

# Get the registry edition for an IBAN country (note: IIBAN country 'AA' returns 'N/A')
$country_registry_edition = $myCountry->RegistryEdition();

# Determine whether an IBAN country is an official, SWIFT issued country record
if(!$myCountry->SWIFTOfficial()) {
 # ... do something against decentralization ...
}

# Get the IANA code for an IBAN country
$country_iana = $myCountry->IANA();

# Get the ISO3166-1 alpha-2 code for an IBAN country
$country_iso3166 = $myCountry->ISO3166();

# Get the parent registrar IBAN country of an IBAN country
# (Returns '' in the normal case that the country is independently registered)
$registrar_country = $myCountry->ParentRegistrar();
if($registrar_country=='') {
 print "The mighty nation of '$iban_country' stands strong and proud...\n";
 print " ... with its own heirarchy of bureaucrats!\n";
}
else {
 print "It has been foretold that the downtrodden natives of '$iban_country' will one day\n";
 print "rise up and throw off the shackles of the evil '$registrar_country' oppressors!\n";
}

# Get the official currency of an IBAN country as an ISO4217 alpha code
# (Returns '' in the Internet (IIBAN) case, ie. no official currency)
$official_currency = $myCountry->CurrencyISO4217();
if($official_currency == '') {
 print "There is no official currency for the IBAN country '$iban_country'.\n";
}

# Get the URL of an IBAN country's central bank
# (Note: Returns '' if there is no central bank. Also, note that
#        sometimes multiple countries share one central bank)
$central_bank_url = $myCountry->CentralBankURL();

# Get the name of an IBAN country's central bank
# (Note: Returns '' if there is no central bank. Also, note that
#        sometimes multiple countries share one central bank)
$central_bank_name = $myCountry->CentralBankName();

Parsing Functions

# Get an array of all the parts from an IBAN
$iban_parts = $myIban->Parts();

# Get the country part from an IBAN
$iban_country = $myIban->Country();

# Get the checksum part from an IBAN
$checksum = $myIban->Checksum();

# Get the BBAN part from an IBAN
$bban = $myIban->BBAN();

# Get the Bank ID (institution code) from an IBAN
$bank = $myIban->Bank();

# Get the Branch ID (sort code) from an IBAN
#  (NOTE: only available for some countries)
$sortcode = $myIban->Branch();

# Get the (branch-local) account ID from an IBAN
#  (NOTE: only available for some countries)
$account = $myIban->Account();

# Get the national checksum part from an IBAN
#  (NOTE: only available for some countries)
$checksum = $myIban->NationalChecksum();

IBAN Libraries in Other Languages

See for yourself how our approach and features compare favourably with all of these libraries...

Language Library
C# iban-api-net
Java iban-api-java
Java iban4j
Java java-iban
Javascript iban.js
Javascript ng-iban
ObjectiveC IBAN-Helper
ObjectiveC ibanValidation
Perl various CPAN libraries
Python django-localflavor
Python iban-generator
Ruby bank
Ruby iban-tools
Ruby ibandit
Ruby ibanizator
Ruby iso-iban