我以前从未使用过这些函数,但在阅读了很多关于 sprintf() 的内容后,我决定我应该了解它。
所以我继续进行了以下操作。
function currentDateTime() {
list($micro, $Unixtime) = explode(" ",microtime());
$sec= $micro + date("s", $Unixtime);
$sec = mb_ereg_replace(sprintf('%d', $sec), "", ($micro + date("s", $Unixtime)));
return date("Y-m-d H:i:s", $Unixtime).$sec;
}
sprintf(currentDateTime());
它什么都不打印。另一方面使用 printf() 函数:
printf(currentDateTime());
它打印的结果很好。那么这两个函数有什么区别,我该如何正确使用 sprintf() 函数?
最佳答案
sprintf()
返回一个字符串,printf()
显示它。
下面两个是相等的:
printf(currentDateTime());
print sprintf(currentDateTime());
关于php - 为什么 sprintf() 不输出任何东西?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1021743/