What are some alternative methods to preg_replace for formatting and highlighting specific parts of an IBAN number in PHP?

When formatting and highlighting specific parts of an IBAN number in PHP, an alternative method to preg_replace is to use substr_replace to manipulate the string directly. This method allows for more precise control over the formatting and highlighting of specific parts of the IBAN number.

$iban = 'GB29NWBK60161331926819';
$formatted_iban = substr_replace($iban, ' ', 4, 0); // Insert a space after the 4th character
$formatted_iban = substr_replace($formatted_iban, ' ', 9, 0); // Insert a space after the 9th character
echo $formatted_iban;