PHP microtime() 返回如下内容:
0.56876200 1385731177 //that's msec sec
我需要这种格式的值:
1385731177056876200 //this is sec msec without space and dot
目前我正在做这样的事情:
$microtime = microtime();
$microtime_array = explode(" ", $microtime);
$value = $microtime_array[1] . str_replace(".", "", $microtime_array[0]);
有没有一行代码可以实现这一点?
您可以使用正则表达式在一行中完成整个操作:
$value = preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', microtime());
Example:
<?php
$microtime = microtime();
var_dump( $microtime );
var_dump( preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', $microtime) );
?>
Output:
string(21) "0.49323800 1385734417"
string(19) "1385734417049323800"
DEMO http://codepad.org/BSqp0LYv
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)