$version = way_to_get_version();print $version;would print 5.3.0 on one machine, and 5.3.1 on another machine.
Bạn đang xem: How to check and print php version on linux / unix
$version = phpversion();print $version;Documentation
However, for best practice, I would use the constant PHP_VERSION. No function overhead, & cleaner IMO.
Also, be sure lớn use version_compare() if you are comparing PHP versions for compatibility.
Technically the best way lớn do it is with the constant PHP_VERSION as it requires no function gọi và the overhead that comes with it.
emang lại PHP_VERSION;constants are always faster then function calls.
You can either use the phpversion() function or the PHP_VERSION constant.
To compare versions you should always rely on version_compare().
phpversion() is one way. As John conde said, PHP_VERSION is another (that I didn"t know about "till now).
You may also be interested in function_exists()
If you typecast the output of phpversion() lớn a floating point number, it will give sầu you the major và minor version parts. This way you can implement PHP compatibility easily.
$version = (float)phpversion();if ($version > 7.0) //bởi something for php7.1 và above. elseif ($version === 7.0) //vì chưng something for php7.0 else //do something for php5.6 or lower.
Thanks for contributing an answer lớn Staông xã Overflow!
But avoid …Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; bachồng them up with references or personal experience.
To learn more, see our tips on writing great answers.
Post Your Answer Disthẻ
site thiết kế / hình ảnh sản phẩm © 2021 Staông chồng Exchange Inc; user contributions licensed under cc by-sa. rev2021.7.30.39889