phpversion is a function in PHP used to obtain the current PHP version. Its usage syntax is "phpversion(string $extension = ?): string".
#The operating environment of this article: Windows 7 system, PHP version 7.4, Dell G3 computer.
What does php version mean?
phpversion
(PHP 4, PHP 5, PHP 7, PHP 8)
phpversion — Get the current PHP version
Description
phpversion(string $extension = ?): string
Returns a string containing the currently running PHP interpreter or extended version information.
Parameters
extension
Optional extension.
Return value ¶
If the optional parameter extension is specified, phpversion() will return the version of the extension. If there is no corresponding version information, or the extension is not enabled, false is returned.
Example #1 phpversion() Example
<?php // prints e.g. 'Current PHP version: 4.1.1' echo 'Current PHP version: ' . phpversion(); // prints e.g. '2.0' or nothing if the extension isn't enabled echo phpversion('tidy'); ?> 示例 #2 PHP_VERSION_ID 范例和用法 <?php // PHP_VERSION_ID 自 PHP 5.2.7 起有效, // 如果我们的版本低于该版本,则用以下代码来模拟 if (!defined('PHP_VERSION_ID')) { $version = explode('.', PHP_VERSION); define('PHP_VERSION_ID', ($version[0] * 10000 + $version[1] * 100 + $version[2])); } // PHP_VERSION_ID 定义为一个数字,PHP 版本越新,数字越大。 // 它的定义是以下的表达式: // // $version_id = $major_version * 10000 + $minor_version * 100 + $release_version; // // 现在我们可以通过 PHP_VERSION_ID 来检查 PHP 版本, // 而不用每次都必须用 version_compare() 来检查 PHP 是否支持某个功能。 // // 比如,我们在此可以定义一系列 PHP_VERSION_* constants 常量, // 而在 5.2.7 之前的版本并没有被定义。 if (PHP_VERSION_ID < 50207) { define('PHP_MAJOR_VERSION', $version[0]); define('PHP_MINOR_VERSION', $version[1]); define('PHP_RELEASE_VERSION', $version[2]); // 等等, ... } ?>
Comments
Note:
This information also exists in the predefined constant PHP_VERSION. More version information can be obtained using the constants PHP_VERSION_*.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of What does php version mean?. For more information, please follow other related articles on the PHP Chinese website!