How to Get the PHP Version

Sheeraz Gul Feb 15, 2024 PHP PHP Version
  1. Check PHP Version Through PHP
  2. Use phpinfo() With Parameters (Constants) in PHP
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.

Information of 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.

  1. INFO_ALL
  2. INFO_LICENSE
  3. INFO_VARIABLES
  4. INFO_ENVIRONMENT
  5. INFO_MODULES
  6. INFO_CONFIGURATION
  7. INFO_CREDITS

For more information about the constants, click here.

Enjoying our tutorials? Subscribe to DelftStack on YouTube to support us in creating more high-quality video guides. Subscribe
Author: Sheeraz Gul
Sheeraz Gul avatar Sheeraz Gul avatar

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

Related Article - PHP Version