How to Get the PHP Version
This short article will demonstrate how to get your PHP version using built-in functions and constant.
Check PHP Version Through PHP
There are two ways to get an exact version of PHP, one is a built-in function, and the other is constant.
The phpversion()
function gets the current version of your installed PHP.
Example:
<?php
$version = phpversion();
echo "The PHP version is: ". $version;
echo "<br>";
echo "The PHP version is: ".PHP_VERSION;
?>
Output:
The PHP version is: 7.4.27
The PHP version is: 7.4.27
We can also get the version from the PHP info file by using phpinfo()
.
Code:
<?php
// Show all information which equals to phpinfo(INFO_ALL);
phpinfo();
?>
This code will get all the info about installed PHP.
Use phpinfo()
With Parameters (Constants) in PHP
The phpinfo()
function can be combined with the respective constants.
Example:
<?php
// Show the configuration line, the location of the php.ini file, the build date, the Web Server, the System, and more.
phpinfo(INFO_GENERAL);
?>
Here’s the list of the following constants you can also use.
INFO_ALL
INFO_LICENSE
INFO_VARIABLES
INFO_ENVIRONMENT
INFO_MODULES
INFO_CONFIGURATION
INFO_CREDITS
For more information about the constants, click here.
Sheeraz is a Doctorate fellow in Computer Science at Northwestern Polytechnical University, Xian, China. He has 7 years of Software Development experience in AI, Web, Database, and Desktop technologies. He writes tutorials in Java, PHP, Python, GoLang, R, etc., to help beginners learn the field of Computer Science.
LinkedIn Facebook