php microtime()格式值 [英] php microtime() format value
本文介绍了php microtime()格式值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PHP的microtime()返回如下内容:
PHP's microtime() returns something like this:
0.56876200 1385731177 //that's msec sec
该值我需要采用以下格式:
That value I need it in this format:
1385731177056876200 //this is sec msec without space and dot
目前,我正在这样做:
$microtime = microtime();
$microtime_array = explode(" ", $microtime);
$value = $microtime_array[1] . str_replace(".", "", $microtime_array[0]);
有没有一行代码可以实现这一目标?
Is there a one line code to achieve this?
推荐答案
您可以使用正则表达式在一行中完成全部操作:
You can do the entire thing in one line using regex:
$value = preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', microtime());
示例:
<?php
$microtime = microtime();
var_dump( $microtime );
var_dump( preg_replace('/(0)\.(\d+) (\d+)/', '$3$1$2', $microtime) );
?>
输出:
string(21) "0.49323800 1385734417"
string(19) "1385734417049323800"
这篇关于php microtime()格式值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文