Add on to (a function originally written by) "Matias from Argentina": str_format_number function.
Just added handling of $String shorter then $Format by adding a side to start the fill and a string length to the while loop.
<?php
function str_format_number($String, $Format, $Start = 'left'){
if ($Start == 'right') {
$String = strrev($String);
$Format = strrev($Format);
}
if($Format == '') return $String;
if($String == '') return $String;
$Result = '';
$FormatPos = 0;
$StringPos = 0;
while ((strlen($Format) - 1) >= $FormatPos && strlen($String) > $StringPos) {
if (is_numeric(substr($Format, $FormatPos, 1))) {
$Result .= substr($String, $StringPos, 1);
$StringPos++;
} else {
$Result .= substr($Format, $FormatPos, 1);
}
$FormatPos++;
}
if ($Start == 'right') $Result = strrev($Result);
return $Result;
}
?>