I am trying to write a quick string formatting routine to take an unformatted ISRC code and add hyphenation where it is required.
For example, the ISRC USMTD9203901 should translate to US-MTD-92-03901. The pattern is:
[A-Z]{2}-[A-Z]{3}-[0-9]{2}-[0-9]{5}
I have been trying to implement this with substr and this has produced the following block of code:
function formatISRC($isrc) {
$country = substr($isrc, 0, 2);
$label = substr($isrc, 2, 3);
$year = substr($isrc, 5, 2);
$recording = substr($isrc, 7);
return $country.'-'.$label.'-'.$year.'-'.$recording;
}
I am sure there must be a more efficient way of performing string manipulation than this.