The phpversion() retrieves the current PHP version:
<?php echo '<p>PHP Version: '.phpversion().'</p>'; ?>
Output:
PHP Version: 8.1.29
The string returned by phpversion() can easily be converted to a numeric value:
<?php echo '<p>PHP Version: '.phpversion().' = '.(float)phpversion().'</p>'; ?>
Output:
PHP Version: 8.1.29 = 8.1
phpversion() can be used to control the execution of PHP functions with different implementations depending on the PHP version. The following code shows a version-independent application of the microtime() PHP function for retrieving the Unix timestamp with microseconds accuracy:
<?php
function getMicrotime()
{
// Get Unix timestamp with microseconds accuracy
if ((float)phpversion() >= 5.0)
{
return microtime(1);
}
list($usec, $sec) = explode(' ', microtime());
return ((float)$sec + (float)$usec);
}
?>
PHP Function phpversion (INFO) • © 2024 Manfred Baumeister • Updated: 02 October 2010, 23:36 [UTC]
|