Format IBAN with UDT

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
Locked
User avatar
GSM
Forum Members
Forum Members
Posts: 19
Joined: Wed Aug 08, 2007 2:38 pm

Format IBAN with UDT

Post by GSM »

European banking has moved to the IBAN format, replacing the local account numbers. As these new IBAN include not only the account but also country and bank code, their length makes it difficult to read and copy for humans. The recommended format is show them in groups of 4 digits. Using spaces is one way to show them on your website but when copied into the input field of many banks the last digits are cut as the number of digits is limited to the local definition.

Thus a better way to show them that allows to read them properly but copies without spaces is to apply smart formatting via SPAN. This short UDT does exactly that.

Code: Select all

if (isset($params['iban'])) {
  $parts = str_split($params['iban'],4);
  foreach ($parts as $part) {
    echo '<span style="margin-right: 0.3em;">'.$part.'</span>';
  }
} else {
  echo "Parameter 'iban' missing!";
}
Locked

Return to “Tips and Tricks”