如何获得PHP版本? [英] How to get the PHP Version?
本文介绍了如何获得PHP版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以从该脚本中检查执行特定脚本的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;
将在一台计算机上打印5.3.0,在另一台计算机上打印5.3.1.
would print 5.3.0 on one machine, and 5.3.1 on another machine.
推荐答案
$version = phpversion();
print $version;
但是,为了最佳实践,我将使用常量PHP_VERSION
.没有功能开销,更干净的IMO.
However, for best practice, I would use the constant PHP_VERSION
. No function overhead, and cleaner IMO.
此外,如果要比较PHP版本的兼容性,请确保使用version_compare()
.
Also, be sure to use version_compare()
if you are comparing PHP versions for compatibility.
这篇关于如何获得PHP版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文