The 5th Annual China PHP Conference

phpversion

(PHP 4, PHP 5, PHP 7)

phpversionRestituisce la versione del PHP

Descrizione

string phpversion ( void )

Restituisce una stringa contenente la versione dell'interprete PHP.

Nota:

Questa informazione รจ anche disponibile come costante predefinita PHP_VERSION.

Example #1 Esempio di uso di phpversion()

<?php
// Ad esempio visualizza 'Current PHP version: 4.1.1'
echo 'Current PHP version: ' phpversion();
?>

Vedere anche version_compare(), phpinfo(), phpcredits(), php_logo_guid() e zend_version().

add a note add a note

User Contributed Notes 4 notes

up
69
cHao
4 years ago
If you're trying to check whether the version of PHP you're running on is sufficient, don't screw around with `strcasecmp` etc.  PHP already has a `version_compare` function, and it's specifically made to compare PHP-style version strings.

<?php
if (version_compare(phpversion(), '5.3.10', '<')) {
   
// php version isn't high enough
}
?>
up
4
burninleo at gmx dot net
10 months ago
Note that the version string returned by phpversion() may include more information than expected: "5.5.9-1ubuntu4.17", for example.
up
14
pavankumar at tutorvista dot com
6 years ago
To know, what are the {php} extensions loaded & version of extensions :

<?php
foreach (get_loaded_extensions() as $i => $ext)
{
   echo
$ext .' => '. phpversion($ext). '<br/>';
}
?>
up
-1
php at stampy dot me
3 months ago
If you cast the output of phpversion() to a float, it will give you the major and minor version parts as a floating point number.

This will be less useful if the minor version number is 10 or above, but for lower version numbers it works nicely.

<?
$ver
= (float)phpversion();
if (
$ver > 7.0) {
   
//do something for php7.1 and above.
} elseif ($ver === 7.0) {
   
//do something for php7.0
} else {
   
//do something for php5.6 or lower.
}
?>
To Top