My favorite new style of printf
May 20th, 2006 • Related • Filed Under
I just discovered vsprintf()
, which accepts a formatting string and an array of arguments:
// logging function that accepts printf-style formatting
// it prints a time stamp, the string, and a new line
function logf() {
$date = date(DATE_RSS);
$args = func_get_args();
$format = array_shift($args);
return print "$date: " . vsprintf($format, $args) . "\n";
}
Just sharing.
Comment by Jeffrey McManus on 23 May 2006:
stolen from c# I suspect.
Comment by Adam Trachtenberg on 23 May 2006:
I think it’s from Unix, wise guy. Don’t you have a baby to help deliver?