Formatting numbers by tokens with php
- by Adam D
I'm looking for a way to format numbers using "tokens". This needs to be conditional (for the first few leading characters).
Example:
<?php
$styles=array('04## ### ###','0# #### ####','13# ###','1800 ### ###');
format_number(0412345678); /*should return '0412 345 678'*/
format_number(0812345678); /*should return '08 1234 5678'*/
format_number(133622); /*should return '133 622'*/
format_number(1800123456); /*should return '1800 123 456'*/
?>
Incase you haven't guessed, my use of this is to format Australian phone numbers, dependent on their 'type'.
I have a PHP function that does this, but it is ~114 lines and contains a lot of repeated code.
Can anyone help?