php版本比较函数version_compare()
来源:互联网 发布:深思考人工智能薪资 编辑:程序博客网 时间:2024/06/10 06:09
php中比较php版本,一般用version_compare()函数,帮助文档见:http://php.net/manual/en/function.version-compare.php
用途:Compares two "PHP-standardized" version number strings。
语法:version_compare ( string $version1 , string $version2 [, string $operator ] )
具体描述:version_compare() compares two "PHP-standardized" version number strings. This is useful if you would like to write programs working only on some versions of PHP.
The function first replaces _, - and + with a dot . in the version strings and also inserts dots . before and after any non number so that for example '4.3.2RC1' becomes '4.3.2.RC.1'. Then it splits the results like if you were using explode('.', $ver). Then it compares the parts starting from left to right. If a part contains special version strings these are handled in the following order: any string not found in this list < dev < alpha = a < beta = b < RC = rc < # < pl = p. This way not only versions with different levels like '4.1' and '4.1.2' can be compared but also any PHP specific version containing development state.
其中第三个可选参数是比较符:
If you specify the third optional operator argument, you can test for a particular relationship. The possible operators are: <, lt, <=, le, >, gt, >=, ge, ==, =, eq, !=, <>, ne respectively.
This parameter is case-sensitive, so values should be lowercase.
- 返回值:
By default, version_compare() returns -1 if the first version is lower than the second, 0 if they are equal, and 1 if the second is lower.
When using the optional operator argument, the function will return TRUE if the relationship is the one specified by the operator, FALSE otherwise.
从下面的例子,就可以很好地说明version_compare的用法:
<?php
if (version_compare(PHP_VERSION, '6.0.0') >= 0) {
echo 'I am at least PHP version 6.0.0, my version: ' . PHP_VERSION . "/n";
}
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
echo 'I am at least PHP version 5.3.0, my version: ' . PHP_VERSION . "/n";
}
if (version_compare(PHP_VERSION, '5.0.0', '>=')) {
echo 'I am using PHP 5, my version: ' . PHP_VERSION . "/n";
}
if (version_compare(PHP_VERSION, '5.0.0', '<')) {
echo 'I am using PHP 4, my version: ' . PHP_VERSION . "/n";
}
?>
最近在nagios的图表监控插件pnp安装中遇到一个错误提示:Kohana requires PHP 5.2 or newer.查看页面源码,发现如下语句:
version_compare(PHP_VERSION, '5.2', '<') and exit('Kohana requires PHP 5.2 or newer.');
也就是版本不满足就退出。
- php版本比较函数version_compare()
- php版本比较函数version_compare()
- PHP 版本判断 VERSION_COMPARE() 函数
- PHP 版本判断 version_compare() 函数
- PHP实现函数version_compare
- PHP版本比较函数
- version_compare()
- Php版本不同版本比较
- 自定义版本比较函数
- php字符串比较函数
- php字符串比较函数
- php--字符串比较函数
- php字符串比较函数
- php字符串比较函数
- 版本对比函数PHP
- C++软件版本比较函数
- 判断与比较PHP的版本
- PHP比较两个版本的方法
- MSBuild的深入认识
- Android low memory killer 详解
- CDN服务
- dao语言程序
- [转]ARP协议
- php版本比较函数version_compare()
- 协议的补充阅读
- 基于管道的体系结构
- Win7 x64 WDK安装经验
- vs2005 智能感知不正常的解决办法
- x86架构是什么?(转载)
- 交通灯系统
- 结果今天做的一件无语的事!!
- javascript:剪切板的使用(clipboardData.setData)和js中match函数