# Migrating from PHP (laravel-rust-iban)

> This page lists each globalcitizen/php-iban call and its Rust equivalent, for code moving from PHP.

- Package: laravel-rust-iban (Laravel for Rust, alpha), crates: `laravel-rust-iban`, `laravel-rust-iban-core`
- Maintenance: active; Latest release: 0.1.0 (2026-12-05); Framework: laravel-rust 0.2.x; MSRV: Rust 1.99 or later; Licence: MIT
- Links: [Repository](https://github.com/bowerbird-si/laravel-rust-iban), [crates.io](https://crates.io/crates/laravel-rust-iban/0.1.0), [docs.rs](https://docs.rs/laravel-rust-iban/0.1.0), [Changelog](https://oss.bowerbird.si/iban/docs/changelog/), [Contributing](https://github.com/bowerbird-si/laravel-rust-iban/blob/322f32ccaf92144d5d5727285efc84ca03fd603e/CONTRIBUTING.md), [Security policy](https://github.com/bowerbird-si/laravel-rust-iban/blob/322f32ccaf92144d5d5727285efc84ca03fd603e/SECURITY.md)
- Based on: [globalcitizen/php-iban](https://github.com/globalcitizen/php-iban): Reference behavior for the independent Rust implementation.
- PHP parity: core (14 covered, 34 diverged, 11 planned of 59 abilities; 565 fixtures; follows globalcitizen/php-iban v5.03b; verified 2026-12-04)
- Community package, not affiliated with Laravel.
- HTML version: https://oss.bowerbird.si/iban/docs/migrating-from-php/
- Source: https://github.com/bowerbird-si/laravel-rust-iban/blob/322f32ccaf92144d5d5727285efc84ca03fd603e/docs/migrating-from-php.md

This page lists each globalcitizen/php-iban call and its Rust equivalent, for code moving from PHP.

The procedural PHP functions become free functions on `&str`. The PHP `IBAN` and `IBANCountry` classes
become the `Iban` and `Country` types. Some return types change:

- Fallible calls return `Result<_, Error>` where PHP returns `false` or `""`.
- National checks return a `NationalCheck` (`Valid`, `Invalid`, `Unsupported`) where PHP returns
  `true`, `false` or `""`.
- Country fields are typed: lengths are `u8`, flags are `bool`, offsets are `RangeInclusive<usize>`,
  missing values are `None`.

## Validation and formatting

| PHP | Rust |
| --- | --- |
| `verify_iban($iban)` | `verify(iban)`, or `Iban::parse(iban)` to keep the value |
| `verify_iban($iban, true)` | `verify_strict(iban)`, or `Iban::parse_strict(iban)` |
| `iban_to_machine_format($iban)` | `to_machine_format(iban)`, or `iban.machine_format()` |
| `iban_to_human_format($iban)` | `to_human_format(iban)`, or `iban.human_format()` |
| `iban_to_obfuscated_format($iban)` | `to_obfuscated_format(iban)`, or `iban.obfuscated_format()` |
| `iban_mistranscription_suggestions($iban)` | `mistranscription_suggestions(iban)` |

## Check digits

| PHP | Rust |
| --- | --- |
| `iban_verify_checksum($iban)` | `verify_checksum(iban)` |
| `iban_find_checksum($iban)` | `find_checksum(iban)` |
| `iban_set_checksum($iban)` | `set_checksum(iban)` |
| `iban_checksum_string_replace($s)` | `checksum_string_replace(s)` |
| `iban_mod97_10($numeric)` | `mod97_10(numeric)` |
| `iban_mod97_10_checksum($numeric)` | `mod97_10_checksum(numeric)`, a `u8` |
| `iban_verify_nationalchecksum($iban)` | `verify_national_checksum(iban)`, or `iban.national_check()` |
| `iban_find_nationalchecksum($iban)` | `find_national_checksum(iban)` |
| `iban_set_nationalchecksum($iban)` | `set_national_checksum(iban)`, or `iban.with_national_check_digits()` |
| The GMP setting | One arithmetic path handles up to 1024 ASCII digits |

## Parts

| PHP | Rust |
| --- | --- |
| `iban_get_parts($iban)` | `parts(iban)`, or `iban.parts()` |
| `iban_get_country_part($iban)` | `iban.country_code()` |
| `iban_get_checksum_part($iban)` | `iban.check_digits()` |
| `iban_get_bban_part($iban)` | `iban.bban()` |
| `iban_get_bank_part($iban)` | `iban.bank()` |
| `iban_get_branch_part($iban)` | `iban.branch()` |
| `iban_get_account_part($iban)` | `iban.account()` |
| `iban_get_nationalchecksum_part($iban)` | `iban.national_check_digits()` |

The `iban_get_parts()` keys `checksum` and `nationalchecksum` are the `IbanParts` fields
`check_digits` and `national_check_digits`.

## Countries

`IBANCountry::Name()` and the other class methods map to the same `Country` methods as the procedural
functions below. Get a `Country` with `country(code)` or `iban.country()`.

| PHP | Rust |
| --- | --- |
| `iban_countries()` | `countries()`, a slice of `Country`. Call `.code()` on each. |
| `iban_country_get_country_name($code)` | `name()` |
| `iban_country_get_domestic_example($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_bban_example($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_bban_format_swift($code)` | `bban_structure()` |
| `iban_country_get_bban_format_regex($code)` | `bban_pattern()` |
| `iban_country_get_bban_length($code)` | `bban_length()` |
| `iban_country_get_iban_example($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_iban_format_swift($code)` | `iban_structure()` |
| `iban_country_get_iban_format_regex($code)` | `iban_pattern()` |
| `iban_country_get_iban_length($code)` | `iban_length()` |
| `iban_country_get_bankid_start_offset($code)`, `_stop_offset` | `bank_id_range()` |
| `iban_country_get_branchid_start_offset($code)`, `_stop_offset` | `branch_id_range()` |
| `iban_country_get_nationalchecksum_start_offset($code)`, `_stop_offset` | `national_check_digits_range()` |
| `iban_country_get_registry_edition($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_country_swift_official($code)` | `swift_official()` |
| `iban_country_is_sepa($code)` | `is_sepa()` |
| `iban_country_get_iana($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_iso3166($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_parent_registrar($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_currency_iso4217($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_central_bank_url($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_central_bank_name($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_membership($code)` | Deferred beyond v0.1.0 |
| `iban_country_get_is_eu_member($code)` | `is_eu_member()` |

## The IBAN class

`new IBAN($iban)` becomes `Iban::parse(iban)`, which validates the input when it constructs
the value. Instance methods operate on the parsed IBAN. `with_national_check_digits()` returns a
`Result` because national repair can fail. To check a different value, call `verify(other)`.

## Laravel

To validate request input in Laravel for Rust, use [`IbanRule`](https://oss.bowerbird.si/iban/docs/validation/). To format IBANs in
views, use the template filters on the same page.

## Behaviour that changes

The port follows the published standards where PHP's output differs from them: national check digits
for Belgium, Norway, Slovakia, the Netherlands and the MOD 97-10 countries, the check digit range, strict
mode and lower-case letters, short inputs, and the registry data. The
[README](https://github.com/bowerbird-si/laravel-rust-iban#differences-from-php) lists every difference.
