Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the PHP Version?

Tags:

php

Is there a way to check the version of PHP that executed a particular script from within that script? So for example, the following snippet

$version = way_to_get_version(); print $version; 

would print 5.3.0 on one machine, and 5.3.1 on another machine.

like image 948
Bob Avatar asked Jan 22 '10 00:01

Bob


People also ask

What version of PHP is on my server?

The most reliable way of finding out what version of PHP is used for that specific website is to use the phpinfo() function, which prints various information about the PHP server, including its version. Once you find out what PHP version you have, either remove the file or restrict the access to it.


1 Answers

$version = phpversion(); print $version; 

Documentation

However, for best practice, I would use the constant PHP_VERSION. No function overhead, and cleaner IMO.

Also, be sure to use version_compare() if you are comparing PHP versions for compatibility.

like image 52
alex Avatar answered Sep 30 '22 07:09

alex