Original http://www.cnphp6.com/archives/63604
This is how the Version_compare () function is described in the PHP manual:
Version_compare () is used to compare the version number string of two "php normalization. This is useful for writing programs that are compatible with only certain versions of PHP
Mixed Version_compare (String $version 1, String $version 2 [, String $operator])
Back to Mixed type
String $version version 1 required
String $version 2– version 2 must be filled in
String $operator – understood as an operator bar optional
Namely <, LT, <=, le, >, GT, >=, ge, = =, =, eq,!=, <> and NE.
If the third argument is specified, a Boolean is returned, and if the third argument is not specified, there are three of the following:
When the first version is lower than the second version return-1
Return 0 when the first version equals the second version
Return 1 when the first version is higher than the second version
<?php
Header (' Content-type:text/html;charset=utf-8 ');
/**
* To determine whether PHP version is above 5.3.0
/echo ' <pre> ';
I use the version of 5.2.17
Echo ' PHP for the current version of '. Php_version. " \ n ";
Var_dump (Version_compare (php_version, ' 5.2.0 '));
Var_dump (Version_compare (php_version, ' 5.2.0 ', ' = '));
Var_dump (Version_compare (php_version, ' 5.3.0 ', ' ge '));
if (Version_compare (php_version, ' 5.3.0 ', ' ge ')) {
echo ' your PHP version is greater than 5.3.0, the current version is '. php_version;
} else{
Echo ' Your PHP version is less than 5.3.0, the current version is '. php_version;
}
The results are as follows:
The current version of PHP is 5.2.17
int (1) bool (FALSE) bool (false
)
your PHP version is less than 5.3.0, the current version is 5.2.17