我知道回答这个问题可能为时已晚,但这是我使用的功能:
if(!function_exists('CompareVersion')){
function CompareVersion($v1='', $v2='', $s='>'){
# We delete all characters except numbers 0-9
$regex = '/[^0-9]/';
$v1 = preg_replace($regex, '', $v1);
$v2 = preg_replace($regex, '', $v2);
# Wewill get the length of both string
$lgt1 = strlen($v1);
$lgt2 = strlen($v2);
# We will make sure that the length is the same by adding zeros at the end
# Example: 1031 and 30215 - 1031 is smaller then 1031 become 10310
if($lgt2 > $lgt1){
$v1 = str_pad($v1, $lgt2, 0, STR_PAD_RIGHT);
} elseif($lgt1 > $lgt2){
$v2 = str_pad($v2, $lgt1, 0, STR_PAD_RIGHT);
}
# We remove the leading zeros
$v1 = ltrim($v1, 0);
$v2 = ltrim($v2, 0);
# We return the result
switch($s){
case '>': return $v1 > $v2;
case '>=': return $v1 >= $v2;
case '<': return $v1 < $v2;
case '<=': return $v1 <= $v2;
case '=':
case '==': return $v1 == $v2;
case '===': return $v1 === $v2;
case '<>':
case '!=': return $v1 != $v2;
case '!==': return $v1 !== $v2;
}
}
}