Baumeister Mediasoft Engineering BME - Baumeister Mediasoft Engineering  PHP Function phpversion (INFO) - English Version PHP-Funktion phpversion (INFO) - Deutsche Version
Baumeister Mediasoft Engineering
Bartels AutoEngineerCarLogServicesResourcesCompany ProfileContact Us
Baumeister Mediasoft Engineering » Resources » Web Development » PHP » Functions » phpversion
PHP Functions

PHP Function phpversion (INFO)

PHP - PHP Hypertext Preprocessor

The phpversion() retrieves the current PHP version:

<?php
echo '<p>PHP Version: '.phpversion().'</p>';
?>

Output:

PHP Version: 7.2.15

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: 7.2.15 = 7.2

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);
}
?>

Related Topics

Baumeister Mediasoft Engineering » Resources » Web Development » PHP » Functions » phpversion

PHP Function phpversion (INFO) • © 2019 Manfred Baumeister • Updated: 02 October 2010, 23:36 [UTC]

Baumeister Mediasoft Engineering, Clontarf, Dublin 3, D03 HA22, Ireland
© 2019 Manfred Baumeister

PHP Function phpversion (INFO) - English Version PHP-Funktion phpversion (INFO) - Deutsche Version