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
Currently I'm doing something this:
$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());
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With