We can check our PHP version in 2 major ways; via a PHP function and via the command line. The version of PHP which we are using is sometimes important as some scripts rely on functions that are only available in some versions. It is a good idea then to check the version of PHP before using these scripts.
PHP offers a useful function called phpversion which provides us with the current version of the PHP interpreter.
To get the current PHP version from a script, we can use the code below or edit it as necessary:
<?php echo 'Your current PHP version is ' . phpversion(); ?>
The output of this function may be something similar to:
You can use this function in your scripts to add additional compatibility checks especially when the script may run on many different platforms.
We can also check the version of PHP we have by executing a command in the terminal.
Open a command line and execute the following:
php -vYou will get some output similar to the following:
From that you can tell that you are running PHP version 5.0.2.
Those are the 2 major ways provided to check the current PHP version. We hope this PHP tutorial was useful to you.