I am currently using preg_match
to insert a colon after the second character of a four-character string (1000). I think it is an elegant solution. But I wonder if there are any other elegant solutions for this? Thanks for your ideas!
Working code
$string = '1000';
$r = preg_replace('/^.*(\d{2})(\d{2})$/', '$1:$2', $string);
print_r($r);
// output "10:00"