<?php
/**
 * Calculates Czech/Slovak IBAN
 *
 * Note: Garbage in means garbage out, so you should check what you
 *       are sending in as parameters.
 *
 * @author Jirka Pech
 * @copyright 1core, s.r.o.
 * @param string i_account Normal account number which should contain one slash
 * @param string i_country ISO standard country code
 *
 * @return string IBAN International Bank Account Number
 *
 */
function iban($i_account$i_country 'CZ') {
  list(
$bankaccount$bankcode) = split('/'str_replace('-'''str_replace(' '''$i_account)));
  
$country strtoupper($i_country);
  
$x_account str_pad($bankcode4'0'STR_PAD_LEFT)
             . 
str_pad($bankaccount16'0'STR_PAD_LEFT)
             . (
ord($country[0]) - 55)
             . (
ord($country[1]) - 55)
             . 
'00';

  
// we're not using bcmath, so it seems little bit complicated
  
$x_crc '';
  
$x_pos 0;

  while (
strlen($x_account) > 0) {
    
$x_len strlen($x_crc);
    
$x_crc intval($x_crc substr($x_account$x_pos$x_len)) % 97;
    
$x_account substr($x_account$x_len);
  }
  return(
$country str_pad(98 $x_crc2'0'STR_PAD_LEFT) . $bankcode $bankaccount);
?>