Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php microtime() format value

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?

like image 830
Matías Cánepa Avatar asked Oct 12 '25 03:10

Matías Cánepa


1 Answers

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

like image 60
h2ooooooo Avatar answered Oct 14 '25 19:10

h2ooooooo