3v4l.org

run code in 300+ PHP versions simultaneously
<?php function checkIBAN(string $iban): bool { // Normalize input (remove spaces and make uppercase) $iban = strtoupper(str_replace(' ', '', $iban)); if (!preg_match('/^([A-Z]{2})(\d{2})([A-Z\d]{1,30})$/', $iban, $segments)) { return false; } [, $country, $check, $account] = $segments; $digits = str_split(strtr($account . $country, array_combine(range('A', 'Z'), range(10, 35))) . '00'); $first = array_shift($digits); $checksum = array_reduce( $digits, function ($carry, $int) { $carry = ($carry * 10 + (int)$int) % 97; return $carry; }, (int)$first ); return (98 - $checksum) == $check; } var_export(checkIBAN('GB29NWBK60161331926819'));
Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12, 8.1rc1 - rc3
true

preferences:
50.38 ms | 460 KiB | 5 Q