为什么sprintf()不输出任何内容? [英] Why doesn't sprintf() output anything?
本文介绍了为什么sprintf()不输出任何内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我以前从未使用过这些功能,但是在阅读了很多有关sprintf()的内容之后,我决定应该了解它.
I've never used these functions before but after reading a lot about sprintf(), I decided I should get to know it.
所以我继续进行以下操作.
So I went ahead and did the following.
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()函数:
It prints nothing. Using the printf() function on the other hand:
printf(currentDateTime());
它可以很好地打印结果.那么这两个函数有什么区别?我该如何正确使用sprintf()函数?
It prints the result just fine. So what's the difference between these 2 functions and how do I properly use the sprintf() function?
推荐答案
sprintf()
返回一个字符串,printf()
显示它.
sprintf()
returns a string, printf()
displays it.
以下两个相等:
printf(currentDateTime());
print sprintf(currentDateTime());
这篇关于为什么sprintf()不输出任何内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文